Wednesday, January 6, 2010

Setting up a Clojure REPL with Emacs and Slime

I spent a long week trying to get clojure and slime set up in emacs. It was very frustrating with emacs 22 and I never figured it out. These steps work have been tested on Ubuntu 9.10 and OSX 10.6 with emacs 23.

Install Emacs 23. From apt-get or download for osx.

apt-get install emacs
-or-
http://emacsformacosx.com/

Install ELPA [http://tromey.com/elpa/install.html]:

M-x ielm [to fire up the emacs lisp interpreter]

Paste and run the following to install ELPA.

(let ((buffer (url-retrieve-synchronously
"http://tromey.com/elpa/package-install.el)))
(save-excursion
(set-buffer buffer)
(goto-char (point-min))
(re-search-forward "^$" nil 'move)
(eval-region (point) (point-max))
(kill-buffer (current-buffer))))

Install swank-clojure with ELPA:

M-x package-list-packages
Scroll down to swank-clojure and press i.
Press x to start installation.
Close emacs with C-x C-c.

Run swank-clojure with slime and let swank-clojure install it's dependencies:

Start emacs.
M-x slime
Answer yes to have swank-clojure install deps.

Bradford does a good job explaining how to install leiningen in this post so go with that. Once it's installed you can get your first emacs/slime/clojure repl like this:

> mkdir ~/tmp/
> cd ~/tmp/
> lein new test_clojure_repl
> cd test_clojure_repl
> lein deps

Start slime with all the leiningen default dependencies:

Start emacs.
M-x swank-clojure-project
Press enter to choose current directory.

You should now have a nice clojure/clojure-contrib repl.

2 comments:

  1. There is a missing last " in (let ((buffer (url-retrieve-synchronously
    "http://tromey.com/elpa/package-install.el)))

    Regards, Linus Ericsson

    ReplyDelete
  2. Wish this worked, but I got 345 lines of errors terminating in:

    swank-clojure.el:48:1:Error: Cannot open load file: clojure-mode

    ReplyDelete