How to look up CL function definitions inside emacs - emacs

Is there a way to see the arguments for a common lisp function and its documentation from within emacs? Or also to see a list of all available functions?

SLIME automatically loads eldoc-mode - this is the mode that displays function arguments in the minibuffer. If you mean cl library of Emacs Lisp, you can load it using M-xeldoc-mode.
Another useful SLIME feature is the C-c C-d C-d - this pops a new buffer with documentation about the function.
These are very useful too:
C-c C-w C-aslime-who-specializes
C-c C-w C-bslime-who-binds
C-c C-w C-cslime-who-calls
C-c C-w RETslime-who-macroexpands
C-c C-w C-rslime-who-references
C-c C-w C-sslime-who-sets
C-c C-w C-wslime-calls-who
C-c C-w aslime-who-specializes
C-c C-w bslime-who-binds
C-c C-w cslime-who-calls
C-c C-w mslime-who-macroexpands
C-c C-w rslime-who-references
C-c C-w sslime-who-sets
C-c C-w wslime-calls-who
It should be obvious what they do from their names.
Addidionally, there's an auto-complete plugin for SLIME which can show documentation and function arguments in a drop-down menu (well, sort of), visually similar to how Visual Studio or Eclipse do it. I think it's called ac-slime and is installable through ELPA.

You can get the documentation of a function with documentation. (Following examples for getting information about the function list.)
(documentation 'list 'function)
"Returns constructs and returns a list of its arguments."
To get the argument-list, there is typically an implementation dependent function arglist in some package. You can search this function with (apropos 'arglist). This will give you a list of all interned symbols whose names contain arglist.
For example in CMUCL it is (swank-backend::arglist 'list), in CLISP it is just (arglist 'list), etc.
N.B. If you use SLIME, you should see the available arguments below anyway.

Sort of. The manual GNU Emacs Common Lisp Emulation comes with GNU Emacs -- it is CL in the main (dir-level) Info menu. Consult the function index for the list of documented functions. But the documentation is somewhat incomplete, and it documents only the Emacs implementation, which sometimes differs from the Common Lisp spec.
Consult the Common Lisp documentation for precise info about the language.
Common Lisp Hyperspec
Common Lisp the Language, 2nd Edition

Everything below is from http://cl-cookbook.sourceforge.net/emacs-ide.html
Q2. Viewing HyperSpec from within Emacs
Q2 I like having access to the HyperSpec when I'm in Emacs, but why does it have to use an external browser? Why
can't I just see the HyperSpec in Emacs?
A2 If you use the Emacs add-on package W3 (or W3M which provides similar functionality), you can display HTML pages
inside of Emacs. Once you have W3 and the HyperSpec both installed, use code similar to the following to access the
HyperSpec from the Shift-F1 key:
(global-set-key [(shift f1)]
'(lambda ()
(interactive)
(let ((browse-url-browser-function
'browse-url-w3)
(common-lisp-hyperspec-root
"file://c:/home/docs/Hyperspec/")
(common-lisp-hyperspec-symbol-table
(concat common-lisp-hyperspec-root
"Data/Map_Sym.txt"))
(hyperspec-prog
"c:/home/site/ilisp/extra/hyperspec"))
(load-library hyperspec-prog)
(common-lisp-hyperspec
(thing-at-point 'symbol)))))
Note that the "let" in the above code sets the browse-url-browser-function to W3 for just the HyperSpec. You can
either set the variable globally (if you want to always use W3 or some other specific browser) or locally (if you
want to use a specific browser and not the default one).

Related

Slime Autocompletion when editing file

I am new to Lisp. I installed LIsp in a box to learn Common Lisp. In the slime-repl I can use autocompletion using the tab key. However I want to do so in other buffers - files - I edit. For instance I want to do the following:
C-x b ;; Here I switch to the buffer corresponding to my file. S I am not in the repl anymore.
(remove-i ;; Here I use the tab key, but nothing occurs.
In the repl buffer, I can type (remove-i and I will see matching functions such as remove-if and remove-if-not.
How can I add lisp autocompletion while editing any other file?
C-M-i (translated from <M-tab>) runs the command slime-complete-symbol (found
in slime-mode-indirect-map), which is an interactive compiled Lisp function in
‘slime.el’.
It is bound to C-c TAB, C-M-i, <menu-bar> <SLIME> <Complete Symbol>.
(slime-complete-symbol)
Complete the symbol at point.
Completion is performed by ‘slime-completion-at-point-functions’.
You can bind this function to TAB, if you want.
Peter

How to know emacs true mode names?

Sometimes I copy configuration options from the Internet to my .emacs. Sometimes they don't work.
(add-hook 'laTeX-mode-hook 'turn-on-flyspell)
doesn't work:
(add-hook 'LaTeX-mode-hook 'turn-on-flyspell)
(notice the uppercase in Latex). But,
(add-hook 'flyspell-mode-hook 'flyspell-buffer)
is correct. Although Emacs shows "Fly" in the lower bar and also M-: major-mode shows latex-mode and not Latex-mode.
How do I know how to write emacs modes name?
It sounds like you're actually more interested in the names of modes' hook variables than in the modes themselves.
You have several options. I will suggest some, based around discovering flyspell-mode-hook:
M-x apropos-variable RET flyspell RET, then search the results buffer for hook
C-h v flyspell-, then tab-complete
Any time you are in the minibuffer tab-completion is a good thing to try
M-x find-function flyspell-mode RET will open up the source code for flyspell, you can then search for hook
If you have configured your Emacs to provide completion for Emacs Lisp, you can simply type
(add-hook 'flyspell-
into your .emacs buffer and let Emacs suggest valid completion
Tools like Helm and ido can simplify the process of finding things
Using the find-function technique with latex-mode (which I tab-completed), I discovered that my version of Emacs calls its LaTeX mode function latex-mode. Searching for LaTeX- showed me that LaTeX-mode is an alias for latex-mode.
Your use of M-: major-mode is good, and gives you the correct major mode name (i.e. the symbol name for the mode function).
I don't believe there's a standard function to list the symbol names for the current buffer's enabled minor modes, but you can see all (loaded) minor mode symbols with C-hv minor-mode-list, so it's not hard to verify a name if you find you need to.
The symbol name for a mode's hook is literally the mode's symbol name with the suffix -hook.
Minor modes also have (in addition) an -on-hook and -off-hook.
The hook variables don't necessarily exist when not in use, but this naming is hard-coded in the standard macros for defining modes (and running their hooks at the appropriate times); and the modes which don't use those macros invariably follow the same conventions, to ensure consistency.

Clojure documentation in Emacs

Is it possible to view Clojure function documentation in Emacs? Namely, can I configure Emacs to lookup Clojure functions under the cursor?
I'm using clojure-mode and SLIME. Oddly, I can't even use apropos or dir in SLIME's repl, although they're automatically loaded by lein repl.
Try the function slime-describe-symbol, which is usually bound to C-c C-d d.
Place the point somewhere near the function name and hit C-c, then C-d, and then d.
There's also slime-describe-function, bound to C-c C-d f, but I rarely use it, as it's less general than the aforementioned symbol-related lookup function.
To see all the documentation-related functions, press C-c C-d C-h. These bindings are not specific to Clojure; they are instead defined by SLIME, and will work as well if not better for other Lisp dialects.
I find the combination of slime-apropos and eldoc minor mode (make sure you have swank-clojure 1.4.0 as it fixes both of those) better than the slime-describe-symbol/function commands mentioned above.
From SLIME REPL you can run (use 'clojure.repl). This will make functions like apropos and doc available

How do I list all yanks in emacs?

Is there a way to list all the yanked text in Emacs? You can do it on Textmate with SPLAT+V.
Edit: I meant recently killed items, items that can be yanked.
The list of kills (i.e., the list of things you can yank) is called kill ring and stored in the variable kill-ring, so you can view it (in a not very nice way) with C-h v kill-ring RET.
The kill ring also appears in the menu, under “Edit / Paste from kill menu”. If you use a text mode Emacs or have turned the menu bar off, you can access the menu with M-x tmm-menubar (bound to M-`): type M-` e p followed by the first letter of the item you want to paste (if it's a letter and it's unique, otherwise whatever character is indicated). If you don't want to paste anything, type M-` e p C-g; the kills remain in the *Completions* buffer. The kill texts are displayed truncated to yank-menu-length characters.
To my knowledge, emacs doesn't support that feature out of the box.
If you're using a Debian or Ubuntu Linux distribution, you can install the emacs-goodies-el package, which contains a browse-kill-ring feature (bound to M-y by default).
Alternatively, you can use the browse-kill-ring ELisp package available here.
See also here for a nice article about this problem and other alternate solutions.
EmacsWiki has a satisfying list of solutions. A portable and intuitive solution uses the built-in popup.el to display a vertical list to choose from:
(global-set-key (kbd "C-c y") '(lambda ()
(interactive)
(popup-menu 'yank-menu)))
In Icicles you can see all of your kill-ring, and yank any entries in it using completion. By default, C-y is bound in Icicle mode to icicle-yank-maybe-completing.
That's the same as yank, unless you give it a negative prefix arg (e.g., C--). In that case, it lets you complete against the kill-ring. Completion can be prefix, apropos (substring, regexp), or fuzzy.
http://www.emacswiki.org/emacs/Icicles_-_Multi-Commands
councel-yank-pop wors well for me
especially with the binding suggested in
http://pragmaticemacs.com/emacs/counsel-yank-pop-with-a-tweak/
(use-package counsel
:bind
(("M-y" . counsel-yank-pop)
:map ivy-minibuffer-map
("M-y" . ivy-next-line)))
if you use helm, you may call the helm-show-kill-ring function.

OCaml Emacs Tuareg: Evaluate phrase keyboard shortcut, and how to display actual greek symbols?

Two questions about Emacs Tuareg for OCaml:
I have seen some configurations where it displays an alpha symbol instead of a'. How can I turn this on?
What is the keyboard shortcut for "evaluate phrase" or "evaluate buffer"?
I can only answer part (2):
To start an Ocaml top-level: C-c C-s
To evaluate a phrase: C-x C-e
To evaluate a buffer: C-c C-b
To evaluate a region: C-c C-r
Launch the tuareg mode (e.g. by M-x tuareg-mode), and look at its documentation pressing C-h m.
The symbols are displayed by the sym-lock mode only works for Xemacs and its variants I'm afraid, but you'll find how to configure it in your .emacs in the help mentioned above. The shortcut to execute a statement is C-x C-e (see section 'Special keys' of the help).
I'm not sure if this is exactly what you mean for part 1 of your question, but I have a font-lock-mode keyword to display the lambda keyword as the Greek lambda symbol, which could be adapted to do what you ask. It only requires that font-lock-mode be enabled. (I didn't write it, just found it floating around somewhere).
;; real lisp hackers use the lambda character
;; courtesy of stefan monnier on c.l.l
(defun sm-lambda-mode-hook ()
(font-lock-add-keywords
nil `(("\\<lambda\\>"
(0 (progn (compose-region (match-beginning 0) (match-end 0)
,(make-char 'greek-iso8859-7 107))
nil))))))
(add-hook 'emacs-lisp-mode-hook 'sm-lambda-mode-hook)
(add-hook 'lisp-interactive-mode-hook 'sm-lamba-mode-hook)
(add-hook 'scheme-mode-hook 'sm-lambda-mode-hook)
You can look to my existing configs, based on the code from EmacsWiki with some extensions - function to handle conversion from text to chars, and example of it use for erlang mode - you can change it for ocaml mode also
P.S. but this code has one disadvantage - it also displays these characters inside strings and comments