02 October 2014

I’ve been hacking Clojure for many years now, and I’ve been happy to rekindle my love for Emacs. The Clojure/Emacs tool-chain has come a long way during this time, swank-clojure, nREPL, nrepl.el and now Cider. The feature list is ever growing, and every-time you look there are some new awesome shortcut that will ‘make your day’.

However, the last couple of months have been rough for the Cider project. I’ve experienced lots of instability, crashes and hanged UIs. Cider has become very complex and is starting to feel bloated. I went from Visual Studio to the simpler & snappier Emacs for a reason, and there is a part of me that feel concerned that Cider is ‘re-inventing’ an IDE inside Emacs. If you want a full Clojure/IDE experience with all the bells and whistles, check out Cursive Clojure, its great.

In this post I’ll describe a simpler Emacs/Clojure setup that I’ve been using for the last couple of weeks. It’s much closer to ‘vanilla Emacs’ and thus have much fewer features. On the flip side, it’s very fast and super stable.

It’s based on Emacs standard way to talk to Lisp REPLs, inferior-lisp-mode. This setup bypasses nREPL completely, it simply launches lein repl in a buffer and communicates via stdin/stdout.

The setup consists of the following emacs modes (all available on Melpa);


Here’s some relevant snippets from my init.el, the full file can be found here;

A repl session with this setup

I typically start with loading the project.clj file of the project I want to work on. Then I’ll do a M-x run-lisp, this will launch a repl in the *inferior-lisp* buffer. Now you can go ahead and type what you like in that buffer. Typically I would do (load-dev) and (reset) to start my component system.

I also have a growing number of snippets for REPL convenience, see here.

Edit text like normal, C-c C-e to eval sexpr under point and C-c C-k to eval a file (see above).

Running tests are done manually in the REPL buffer. I typically do (run-tests) or (test-vars [...]). I strongly recommend having humane test output enabled.

Code navigation and auto-complete

Make sure you have Exuberant ctags installed on your system; apt-get install exuberant-ctags or brew install ctags.

You will also need to add --langmap=Lisp:+.clj.cljs into ~/.ctags; see here.

Then use C-c p R to rebuild your TAGS file (this works when you’re in projectile mode). After that just can either do M-. to jump to definition (and C-u M-. for next match), remember that M-* takes you back. One great thing about tags is that you don’t have to be ‘jacked in’ to use them! That goes for both navigation and auto-complete.

That’s it really, nice and simple! If you have any additions to make this setup even better I’d love to hear about them.



Share this post

blog comments powered by Disqus