Setting up emacs/slime/swank for clojure with leiningen
Frage
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-in
which 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!
Lösung
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.
Andere Tipps
I wrote a beginner's guide for setting up Emacs + nREPL client with auto-complete and documentation popup since most old instructions weren't appropriate. Available here. May be helpful for newcomers.
No need to install lein swank plugin. You can add the dependencies in the project.clj file and just lein swank
& M-x slime-connect
.
Try with swank-clojure "1.2.1", it works for me.
Try to do the following, which works for me with Emacs 24 on Ubuntu:
- Install Leiningen. Make sure the directory where you install
lein
is on the$PATH
! Install swank-clojure plugin:
lein plugin install swank-clojure 1.3.3
Create a new project with
lein new
. Do not addswank-clojure
to the:dev-dependencies
. (You really only need one or the other, the plugin or the entry in:dev-dependencies
.)Start Emacs, making sure it can "see"
lein
on the$PATH
, e.g. like this:PATH=$PATH:/path-to/dir-where/lein-is emacs
(Use this command to try it out. For permanent use you should update the
$PATH
in your.profile
file or installlein
in a location that's already on the$PATH
. In a standard Ubuntu install,~/bin
should be on the$PATH
.)Open a file from the project, e.g.
project.clj
, and runM-x clojure-jack-in
. This should start the Swank server and connect the SLIME REPL to it.
this happened to me when i cloned someone else's clojure project from an older version. their project.clj had:
:dev-dependencies [[lein-clojars "0.5.0"]
[swank-clojure "1.2.1"]]
which is incorrect, i think, if you're using M-x clojure-jack-in
. removing these lines, running lein deps
and jacking in worked for me.