Clojure documentation in Emacs - 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

Related

Paredit Wrap Round command not bound to M-(

I'm using Paredit and was studying the cheatsheet. The source and documentation suggest that M-( should trigger paredit-wrap-round but on my system when I use C-h k M-( to find the keybinding for M-( I get:
M-( runs the command paredit-backward-slurp-sexp, which is an
interactive compiled Lisp function in `paredit.el'.
It is bound to <C-M-left>, C-(, ESC <C-left>, M-(.
...
How do I find out what is rebinding M-( to paredit-backward-slurp-sexp and make it back to normal?
You can use an external tool: describe-key-and-map-briefly to find out which keymap the definition is coming from, then advice around define-key to log load-file-name to show where the guilty call is coming from.
Before all that, you probably want to make sure your version of paredit isn't doing anything weird by using emacs -Q and loading just paredit and checking the bindings.

Highlight julia code in emacs

I would like to write julialang code in emacs. Is there an easy way to do it like, for example, when you do python code (all these reserved words in colors and indentation)?
Here is what I have done so far:
I created the file
~/.emacs.d/init.el
with the line (after cloning https://github.com/emacs-ess/ESS/wiki/Julia):
(load "/path-to-ESS/ESS/lisp/ess-site.el")
julia is in my path also. Still, emacs does not recognize julia code
I think that this may help. It seems to be emacs support for Julia.
emacs-ess / ESS
Julia
Overview
ESS support for julia language, among other things, includes
font-lock, indentation, sending code to sub-process, interactive
documentation, imenu, completion and eldoc.
Usage
Start
To start julia type M-x julia RET. You can start multiple julia
processes if you so desire.
To autostart or switch form script to julia subprocess use C-c C-z. To
switch from process buffer to the most recent script buffer also use
C-c C-z. To associate a buffer with a different julia process press
C-c C-s.
Evaluation
To send chunks of code from your script use C-c C-c, C-M-x, C-RET etc.
To load the whole file: C-c C-l. See evaluating code section in ESS
manual. (tip: look up the documentation string of these commands with
for example C-h k C-c C-c)
Help
To access documentation for any help topic or object use C-c C-d C-d.
To call apropos: C-c C-d C-a. To look up for a topic in julia standard
library reference: C-c C-d C-r. To look up a topic in the julia
manual: C-c C-d m. To search julia website: C-c C-d C-w.
To see all help commands defined in ess-doc-map: C-c C-d C-h. See Help
section in ESS documentation.

How to look up CL function definitions inside 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).

How do I determine why emacs indented a certain amount?

In Emacs I'm editing some source code, and I hit <tab>. Emacs indents the line to n spaces. I'd like to change the amount that indents for that kind of line. How do I figure out what rule emacs applied to indent that line by n spaces?
I want to change n, but I need to figure out which of the many indentation-related variables Emacs just used.
A generic answer is difficult. Some modes will make this more apparent than others, but in the general case (as they are free to implement indentation however they wish) I don't think you'll get away from needing to read some elisp.
Starting with the binding for TAB will work, but might be slightly time-consuming depending on how many layers of indirection are involved.
If you know that the major mode in question implements its own indentation, then one (non-rigorous, but fast) approach that you could try to help track down the functions being called is to use ELP, the built in elisp profiler. elp-instrument-package will instrument for profiling all functions with names matching the prefix string argument you specify. Therefore you might do something like the following in a PHP file (noting that php-mode tells you that it is derived from c-mode)
M-x elp-instrument-package RET php- RET
M-x elp-instrument-package RET c- RET
M-x elp-instrument-package RET indent RET
Now type TAB in your source code, and run M-x elp-results to see which of those instrumented functions were called.
At this point you're on your own -- look for the likely suspects, and see what the code is doing -- but it can be a handy way to filter the search.
Once you've finished, use M-x elp-restore-all to prevent any further profiling.
If you're using a mode based on cc-mode (e.g. c-mode, c++-mode, java-mode, etc.), you can hit C-c C-s and it'll tell you what syntactic category the line is. If you want to change it, hit C-c C-o and you'll be guided through the process. Check out the cc-mode docs on customization for more details: https://www.gnu.org/s/emacs/manual/html_node/ccmode/Customizing-Indentation.html
If you happen to enjoy getting your hands really dirty, there's always the elisp debugger to tell you just what Emacs is up to.
If you hit C-h k TAB you'll find the function that Emacs is running (e.g. indent-for-tab-command) then you can do M-x debug-on-entry RET indent-for-tab-command RET. Now whenever you hit TAB you'll pop up a debugger and can watch the execution step by step.
Depending on your taste for debugging, it's either a maddening or enlightening experience. Either way, don't forget to M-x cancel-debug-on-entry when you're done.

What are the good things about slime?

As I asked here, I couldn't make it run Aquamacs/slime/clojure, but I could use Auqamacs/clojure with 'M-x conjure-mode', then C-c C-z (run clojure) and C-c C-e (run expression).
I don't have an experience with SLIME, but I feel that C-c C-z and C-c C-e is just enough for lisp/conjure REPL or debugging.
What features SLIME has more than these features? What people use SLIME for?
So, so, so much more.
M-. to go to a definition.
C-c C-k to compile the current buffer.
M-p & M-n to go forwards and backward in REPL history.
M-<tab> for completion.
A debugger. A wonderful REPL.
And so much more.
Slime gives so much: look at its manual.
It shouldn't be too hard to set up: this post is a great starting point.
Tab completion of java class members in addition to clojure functions and such.
Apart from what had already been said:
Highlighting errors, warnings and notes in source code buffers.
Inspector. An object viewer.
Paredit. Paredit adds comfort and ease to editing lisp code.
Macroexpansion.