Emacs and Slime: Your Lisp Lab

This post goes to who’s studying Clojure (or other Lisp implementations) and is having trouble configuring Emacs. Be prepared for a huge amount of ugly workarounds.

ELPA

The first thing I do on a fresh Emacs installation is configure the ELPA, or Emacs Lisp Package Archive. If you don’t know what ELPA is, think of it as an apt-get for Emacs (with some quirks though, as discussed below).

You can find the installation instructions here. If everything works, now you should be able to run the command M-x package-list-packages <ENTER>. Read this if you don’t understand how commands and shortcuts work on Emacs.

The list of packages available for installation via ELPA should be displayed in a secondary buffer after a few seconds.

Clojure-Mode

Place the cursor over the line that describes the swank-clojure package, and press I to check it for installation. Do the same thing with paredit. If other packages were checked by accident, move the cursor to the correspondent lines and press U to undo the selection. When you’re done, press X to proceed with the installation.

Then, run the command M-x slime <ENTER>, and Emacs will ask if you want it to download the Clojure JAR files for you. Unfortunately, answering yes won’t do anything. :-(

To fix this, download the Clojure JAR files manually and put them on ~/.clojure/. Then, download the most recent swank-clojure JAR file and put it on ~/.swank-clojure/.

There you go. Restart Emacs and run the command M-x slime <ENTER> to start a Clojure REPL inside Emacs!

REPL Clojure

Clojure REPL in Emacs

Remember that Slime provides many useful features like auto-completion, docstring lookup, etc. Check the Slime website for more information.

Other Lisps

Run the following command line to install two of the most popular open source implementations of the ANSI Common Lisp standard, CLISP and SBCL:

$ sudo apt-get install clisp sbcl

Finally, open the file ~/.emacs and paste the following code at the end:

;; paredit + lisp modes
(defvar *lisp-modes* '(clojure-mode-hook lisp-mode-hook emacs-lisp-mode-hook
                       lisp-interaction-mode-hook slime-repl-mode-hook))
 
;; config used in all lisp modes
(defun lisp-config ()
  (paredit-mode t)
  (show-paren-mode t))
 
(mapc (lambda (mode)
        (add-hook mode 'lisp-config)) *lisp-modes*)
 
;; other lisp implementations
(eval-after-load "slime"
  '(progn (setq slime-lisp-implementations
                '((sbcl ("/usr/bin/sbcl"))
                  (clisp ("/usr/bin/clisp"))))))

Swank

The latest versions of Slime come with Swank servers for many popular Lisp implementations, although the package available via ELPA looks like a outdated stripped-down version of Slime. Don’t ask me why.

Let’s fix this. Make sure you have a CVS client installed and then run the following command line to get the latest Slime:

$ cvs -d :pserver:anonymous:anonymous@common-lisp.net:/project/slime/cvsroot co slime

Now, go to the newly created directory slime and copy all files from this directory over the files installed via ELPA in ~/.emacs.d/elpa/slime-<VERSION>. Also remove the file slime.elc from the latter directory as this is a compiled version of an old file.

Restart Emacs. The command M-x slime <ENTER> still starts a Clojure REPL. To start a SBCL REPL, for example, run the command M-- M-x slime <ENTER>, type sbcl and press <ENTER>.

REPL SBCL

SBCL REPL in Emacs

“Jeez, I never saw that many workarounds in a single blog post…”

Everything would be a lot easier if the packages distributed via ELPA were updated more often, so I expect things to get better eventually. I’ll update this post when that happens. (Fingers crossed)

Sobre Daniel Martins

Fundador da Destaquenet, ele é graduado em Sistemas de Informação e desenvolve softwares como hobby e profissão desde 2000. Especializado na plataforma Java, ele utiliza a tecnologia há vários anos, sendo programador e desenvolvedor web certificado pela Sun Microsystems, recentemente adquirida pela Oracle. Também se interessa por assuntos ligados à cultura open source, metodologias ágeis, engenharia de software, frameworks e linguagens dinâmicas tais como Python, Ruby e Smalltalk.
Esta entrada foi publicada em English, Tutorials e marcada com a tag , , , , , , , , . Adicione o link permanente aos seus favoritos.

Uma resposta a Emacs and Slime: Your Lisp Lab

  1. Alfredo disse:

    Thanks for the tip! I was just wondernin’ why I was getting the error “can’t locate swank-loader.lisp” on slime startup!
    Great!

Deixe um Comentário

O seu endereço de email não será publicado Campos obrigatórios são marcados *

*

Você pode usar estas tags e atributos de HTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">