emacsclojureslimeswankleiningen

Setting up emacs/slime/swank for clojure with leiningen


Short version: errors when running M-x slime-connect or M-x clojure-jack-in when using lein swank to start the swank server.

I'm using emacs 24.0.50.1 on Ubuntu 10.10. I've installed the following packages in emacs from ELPA: clojure-mode, paredit, slime, slime-repl

I installed leiningen from github & added it to the classpath, then ran lein plugin install swank-clojure 1.3.3. After that I created a new directory ~/tmp/, cd into it and ran: lein new test-project which seemed to setup everything ok. Then I opened up /tmp/new-project/project.clj in emacs and changed it to:

(defproject test-project "1.0.0-SNAPSHOT"
:description "Test Project"
:dependencies [[org.clojure/clojure "1.2.1"]
               [org.clojure/clojure-contrib "1.2.0"]]
:dev-dependencies [[swank-clojure "1.3.3"]])

After that I went back in the /tmp/new-project folder and ran lein deps then lein swank to download the dependencies and start the swank server which gives the output:

Connection opened on local port 4005.

Back in emacs is where I'm having the problem of getting it to connect to the swank server. I've tried opening the core.clj file and running M-x slime-connect which gives the error:

Symbol's function definition is void: define-slime-contrib

Which makes me think it either doesn't see the swank server running or there's some config that needs to be done for it to see the server. I also tried (with the same file open and with project.clj open) M-x clojure-jack-inwhich I assume tries to start the clojure REPL in the project folder but that gives the following:

Debugger entered--Lisp error: (error "Could not start swank server: sh: lein: not found
")
signal(error ("Could not start swank server: sh: lein: not found\n"))
error("Could not start swank server: %s" "sh: lein: not found\n")
clojure-jack-in-sentinel(#<process swank> "exited abnormally with code 127\n")

I was following directions from http://matthias-schneider.org/docs/clojure-setup/ for the emacs packages and lein setup, then started following the Test Configuration instructions from http://riddell.us/ClojureSwankLeiningenWithEmacsOnLinux.html once I had problems getting M-x slime-connect to open a REPL.

Update:

deleted ~/tmp/test-project, uninstalled emacs and /.emacs.d/elpa/ packages, reinstalled emacs, reinstalled clojure-mode and paredit packages, copied ~/.lein into /bin to make sure of no path issues (wasn't sure if /.lein or /.lein/bin needed to be in the path). Ran /.lein/bin/swank-clojure and then opened emacs, opened the project.clj, and tried M-x slime-connect, which now asks me for a host (local default), port (4005 default), says connecting to swank, gives a message about swank and slime versions differing (y or n) y, then the minibuffers gives error in process filter: Lisp connection closed unexpectedly. In the terminal where I ran /.lein/bin/swank-clojure the following java error pops up:

exception in read loop
java.lang.NumberFormatException: For input string: "    a6"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:470)
at swank.core.protocol$read_swank_message.invoke(protocol.clj:41)
at swank.core.connection$read_from_connection.invoke(connection.clj:59)
at swank.core$read_loop.invoke(core.clj:337)
at swank.swank$connection_serve$fn__1486$fn__1487.invoke(swank.clj:32)
at clojure.lang.AFn.applyToHelper(AFn.java:159)
at clojure.lang.AFn.applyTo(AFn.java:151)
at clojure.core$apply.invoke(core.clj:540)
at swank.swank$connection_serve$fn__1486.doInvoke(swank.clj:29)
at clojure.lang.RestFn.invoke(RestFn.java:397)
at clojure.lang.AFn.run(AFn.java:24)
at java.lang.Thread.run(Thread.java:636)

Update: Solved, I needed to uninstall emacs and delete ALL of /.emacs.d/, not just the packages in /elpa/. After reinstalling I only got clojure-mode package, not slime or slime-repl. Can now connect with M-x clojure-jack-in and am ready to do some work!


Solution

  • you don't need to install slime and slime-repl: they are embedded into lein's plugin (see inside the jar: swank-clojure-1.4.0-SNAPSHOT.jar\swank\payload). You have to install just the clojure-mode.

    Also, when "reinstalling", remember to delete also the hidden folder .emacs.d in your $HOME directory, otherwise it will keep your previously downloaded Emacs plugins.

    Finally prefer clojure-jack-in, not slime-connect - just having slime-connect means that you are still having a SLIME inside Emacs, so you didn't remove it.