I've tried a couple of times now to get Clojure with Swank/Slime working in order to use the "clojure-jack-in" command to start the Swank Clojure server. My attempt a few months ago with emacs23 on Xubuntu 11.10 failed. My recent attempt with emacs24 on Fedora 17 failed (see angry tweet).
I finally had success, so I thought I'd do a brief write up on what I did.
First, I did this on my main machine: Xubuntu 11.10. Canonical still does not have an official emacs24 bundle. I decided not to install the emacs24 package from the Cassou PPA, as I've heard others have had problems with it and I didn't know if I would have to uninstall emacs 23 to use it. I toyed with using Nix, but didn't want to make things even more complicated since I've never tried Nix.
I intend to switch over to the Canonical emacs24 package once they have it, so I left my emacs 23 package intact and built emacs 24 from source and installed it into a local directory, rather than the standard global one.
/* ---[ Installing emacs 24 ]--- */
I downloaded the source from http://alpha.gnu.org/gnu/emacs/pretest/.
I installed some required packages in order to compile emacs:
$ sudo apt-get install xorg-dev
$ sudo apt-get install libjpeg-dev libpng-dev libgif-dev libtiff-dev libncurses-dev
I unpacked the source tarball, specified a local install dir, compiled and installed:
$ tar xvfz emacs-24.1-rc.tar.gz
$ cd emacs-24.1
$ ./configure prefix=/home/midpeter444/apps/emacs24
$ make
$ make install # no sudo required, as it installs 'locally'
Then I reset the global links to emacs
$ ls -l /usr/bin/emacs
lrwxrwxrwx 1 root root 23 /usr/bin/emacs -> /etc/alternatives/emacs
$ ls -l /etc/alternatives/emacs
lrwxrwxrwx 1 root root 18 /etc/alternatives/emacs -> /usr/bin/emacs23-x
$ rm /etc/alternatives/emacs
$ ln -s /home/midpeter444/apps/emacs24/bin/emacs /etc/alternatives/emacs
Next I moved my .emacs.d (from emacs23) and made it into a symlink:
$ mv ~/.emacs.d ~/.emacs23.d
$ mkdir ~/.emacs24.d
$ ln -s ~/.emacs24.d ~/.emacs.d
I copied over my init.el and macros.el files into ~/.emacs24.d, started emacs and the installed a bunch of packages via package.el. In order to use the marmalade repository (in addition to GNUs more limited package repo), I added this to my init.el:
(require 'package)
(package-initialize)
(add-to-list 'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/") t)
Then I restarted emacs and installed a bunch of packages:
> M-x package-list-packages
Here's what I chose and it installed into my ~/.emacs.d/elpa
directory:
~/.emacs.d$ ls elpa/
archives key-chord-0.5.20080915
clojure-mode-1.11.5 markdown-mode-1.8.1
clojurescript-mode-0.5 paredit-22
clojure-test-mode-1.6.0 php-mode-1.5.0
coffee-mode-0.3.0 scala-mode-0.0.2
color-theme-6.5.5 thumb-through-0.3
color-theme-vim-insert-mode-0.1 tidy-2.12
feature-mode-0.4 windsize-0.1
find-things-fast-20111123 yaml-mode-0.0.7
groovy-mode-20110609 yasnippet-0.6.1
guru-mode-0.1 yasnippet-bundle-0.6.1
haml-mode-3.0.14 zen-and-art-theme-1.0.1
js2-mode-20090814 zenburn-theme-1.5
json-1.2
Notice that I did NOT install slime or swank - only clojure-mode. (That may have been my problem previous times I tried this.)
I had to move a few other things over from my .emacs23.d that were not in the package.el directory.
If you are new to using package.el, this blog post helped me: http://batsov.com/articles/2012/02/19/package-management-in-emacs-the-good-the-bad-and-the-ugly/
If you are interested in my emacs setup, I have it on GitHub: https://github.com/midpeter444/emacs-setup
/* ---[ Swank Clojure and clojure-jack-in ]--- */
At this point, after a few minor tweaks to my init.el, my emacs is back in working order and looking good, all nicely upgraded to v24. Now time to tackle this Swank, Slime, clojure-jack-in mystery.
Following the instructions at the swank-clojure project, I cd'd into one of my existing leiningen projects and added [lein-swank "1.4.4"]
to the :plugins
section of the project.clj file, so it looks like this:
(defproject learn-congomongo "1.0.0-SNAPSHOT" :description "Learn the CongoMongo Clojure MongoDB driver" :plugins [[lein-swank "1.4.4"]] :dependencies [[org.clojure/clojure "1.4.0"] [congomongo "0.1.9"]])
Then the magic moment:
> M-x clojure-jack-in
After an excruciatingly long wait with bated breath, it downloaded slime and swank and it loaded the REPL successfully. Success!
Now I just have to learn how to use it and all those fancy keystrokes it allows.
[22-Aug-2012 Update]: Phil Hagelberg tweeted that Swank Clojure is now deprecated in favor of nrepl.el.
I never did get Clojure Swank to work right on my system, so I dropped back to doing M-x inferior-lisp
which works pretty good with Clojure 1.3, 1.4 and 1.5-alpha (the ones I've been using lately). I look forward to trying out nrepl.el.
If you're looking to get slime auto completion and other goodness, you might be interested in Emacs Live: http://github.com/overtone/emacs-live
ReplyDelete