Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do automatic expansion or autocomplete of functions and variables in a Clojure repl

Is there a way to expand the current command at the Clojure repl like I'd be able to do in Common Lisp?

For example say I have typed:

Math/

I would like the tab key to expand to all the available variables and functions in that namespace.

I'm using Clojure as inferior-lisp would like to know how to do this from the plain vanilla repl in Clojure, and through swank slime.

like image 385
justinhj Avatar asked Nov 27 '10 00:11

justinhj


2 Answers

Another vote in favour of clojure-mode and slime under Emacs. In particular, if you set up auto-complete, then you can use my ac-slime package to get context-aware tab completion in a dropdown list. Here's a screencast showing it in action.

And, further to technomancy's comment about hippie-expand, here's how to tie slime completion into hippie-expand.

Update: as of 2012, nrepl, nrepl.el and ac-nrepl are replacing slime and ac-slime; same functionality, smaller and cleaner codebase.

Update2: as of Oct 2013 nrepl.el is renamed to cider and it and ac-nrepl have moved to the clojure-emacs organisation on github. nrepl remains as the server component

like image 185
sanityinc Avatar answered Nov 05 '22 23:11

sanityinc


Have you tried Clojure mode for Emacs? It has autocomplete (suggestions are shown in new window, and if there's only one possible option, it is used to expand name), highlighting and many other nice features (not more then for CL, but not less too).

It is available via ELPA. After installing ELPA type M-x package-list-packages, set cursor near needed package and press i (already installed packages are in red). You'll need packages clojure-mode, slime, slime-repl and swank-clojure. When you're done with i-marks, press x to complete installation. Finally, press M-x slime - Emacs will tell, that Clojure is not installed and propose to download and use latest version. Just agree.

You can also integrate Emacs with Leiningen.

like image 24
ffriend Avatar answered Nov 05 '22 22:11

ffriend