Skip to content
dcj edited this page Apr 4, 2011 · 9 revisions

This page assumes you have already installed and configured clojure-mode and slime.

You should make sure your project.clj file includes [swank-clojure “1.3.0”] under :dev-dependencies. Then run “lein deps”.

From your project directory you can run the following:

$ lein swank

A REPL should get started up on port 4005. Launch Emacs. Once Emacs is up and running type M-x slime-connect. Use the default settings. You’re now connected to a Clojure REPL with a properly configured classpath.

If you’d like to do it all in one M-x command, you can use this:

(defun lein-swank ()
  (interactive)
  (let ((root (locate-dominating-file default-directory "project.clj")))
    (when (not root)
      (error "Not in a Leiningen project."))
    ;; you can customize slime-port using .dir-locals.el
    (shell-command (format "cd %s && lein swank %s &" root slime-port)
                   "*lein-swank*")
    (set-process-filter (get-buffer-process "*lein-swank*")
                        (lambda (process output)
                          (when (string-match "Connection opened on" output)
                            (slime-connect "localhost" slime-port)
                            (set-process-filter process nil))))
    (message "Starting swank server...")))

The default port is 4005. If you’d like to run multiple swank servers, you can choose your own port manually or you can set the slime-port variable on a per-project basis with a directory-local variables file.

Clone this wiki locally