Emacs Setup (+ CL Clojure slime)
This page is born out of my struggle the last few days – to setup a working Emacs + CommonLisp + Clojure + Slime/Swank integration. If you are looking for the copy-paste instructions and don’t care about why go on to the Copy Paste Steps section.
A few points about the why…
- Why do I want to use CL and Clojure? a) I want to learn lisp, 2) I want to learn Clojure as everyone’s going to rah-rah about it, c) Land of Lisp – I love the book and am going through all the games one by one.
- Why Emacs? My editor of choice is (was?) TextMate – but the clojure integration leaves something to be desired (comment if you want more details). Tried Netbeans – it has great out-of-box support and I was happy for a few days. But I started missing power-editing (moving around in files/project etc.) – this is when I saw some screencasts of experts using Emacs+Slime+Clojure – and decided #iGottaHaveThat! Read The Grand Tour Clojure IDEs for more details.
Fine… but the “standard” setups didn’t work for you?
There are quite a few great resources that talk about how to set up:
Emacs with Clojure
- The get clojure section at learn-clojure.com is a great summary (basically Emacs + emacs-starter-kit + leiningen)
- StackOverflow: A gentle tutorial to Emacs/Swank/Paredit/Clojure
Emacs with CL
… but what I wanted to setup both with Emacs. And this turned to be hard. After a lot of contacts in the #Clojure IRC channel, with various people and going through a lot of SO questions I still got nowhere. See this question I posted on SO to get the details of what was broken. Basically slime was not connecting to CL as it was using the stripped-down version from ELPA and I was getting this error:
slime-connection: Not connected.
Polling "/var/folders/B9/B9B5.../-Tmp-/slime.3202".. (Abort with `M-x slime-abort-connection'.) [69 times]
Finally spacemanaki provided a working solution. Admittedly this is fragile – but I am willing to live with a fragile setup to have a working one.
However, this combined with what I had already done to this point was a looot of steps – something I probably won’t remember a month from now. Hence…
Enough! Just gimme the copy-paste steps
These steps will work perfectly on a Mac and probably on Linux – for Windows you’ll probably have to do better:
-
Get Emacs
– I chose GNU Emacs – I’ve seen errors on v22 – so make sure you pick at least Emacs 23.2 -
emacs-starter-kit
I have my fork of it (with my own arnab.el and arnab/), suggest you do too (so you can have your customizations shared across machines). I also put it in my .emacs.d dir (if you have a .emacs.d or .emacs you should move them aside):cd ~/.emacs.d git clone your-clone-of-esk -
Symlink esk to .emacs.d
cd ~/.emacs.d ln -sf emacs-starter-kit/* .… a caveat is that if you add new files (no reason you should add files outside of your username dir, but if you do) you’ll need to symlink them again.
-
Check your setup:
Start Emacs – it’ll compile/install stuff – that’s fine. Next start should be clean (no errors) -
Install packages:
M-x package-list-packagesand press i on clojure-mode, slime and slime-repl, then x to start installation -
Check your setup:
Restart Emacs and see that you get no errors. Now let’s hack it to make it work with both CL and Clojure -
Move slime and slime-repl from elpa over:
The elpa provided packages are bare-bone and will not work with CL. So:cd ~/.emacs.d mkdir managed-packages cd managed-packages mkdir slime-from-cvs slime-from-elpa mv ~/.emacs.d/emacs-starter-kit/elpa/slime-20100404.1 ~/.emacs.d/managed-packages/slime-from-elpa mv ~/.emacs.d/emacs-starter-kit/elpa/slime-repl-20100404 ~/.emacs.d/managed-packages/slime-from-elpa -
Get slime from CVS:
cd ~/.emacs.d/managed-packages/slime-from-cvs cvs -d :pserver:anonymous@common-lisp.net:/project/slime/cvsroot login cvs -d :pserver:anonymous@common-lisp.net:/project/slime/cvsroot checkout slime -
Restart Emacs
If you see no errors you’re probably all set. Let’s verify by learning how to use these tweaks.
Ok – how do I run CL and/or Clojure now?
What we did was separate out slime-from-cvs and slime-from-elpa and added a bit of ELisp to be able to choose one on interactively – see the arnab/lisp.el. Thanks again spacemanaki for the fix. BTW remember to restart emacs if you want to switch from one to the other. So to use:
CommonLisp
Start emacs, M-x slime-common-lisp. Try C-x C-e, C-c C-k in a .lisp file to see it working.
You might have to turn on slime-mode too (M-x slime-mode) if you see errors like “slime C-c C-k is undefined” when you try to compile-and-load (C-c C-k).
If it’s not working for some reason look at the Messages buffer (C-x b to choose buffers)
Clojure
I went with the leiningen way – but at this point you might get swank-clojure working too (to hack random .clj files, outside of lein projects). But since setting up lein is so easy I went with that.
If you don’t have lein, brew it:
brew install leiningen
which lein # should show it now.
… if you have lost me at this point, check out the super awesome homebrew project.
cd into an existing lein project, or create one (lein new project-name). See that the project.clj defines a development dependency on swank-clojure. If not, add it, like: :dev-dependencies [[swank-clojure "1.2.1"]
lein deps # or lein uberjar
lein swank
… this will start a swank-clojure server on localhost:4005.
Connect to it M-x slime-connect-clojure. Try C-x C-e, C-c C-k in the project’s .clj files to see it working.
That’s it! Enjoy!

Hey, quick question – does Paredit work for you when you enable it inside SLIME? When I followed my own notes to set this up again, and then connect to Clojure or Common Lisp with SLIME, and do M-x enable-paredit-mode, it will insert closing parentheses but will not delete them when it should. Let me know! Thanks!
RE: my previous comment, I figured it out. If you have the same issue, take a look at the Emacs Lisp on this page: http://www.emacswiki.org/emacs/ParEdit#toc3
This is really nice and helpful piece of information. I’m satisfied that you simply shared this useful information with us. Please stay us up to date with your comments. Thanks for sharing.