Setting up emacs/slime/swank for clojure with leiningen
Asked Answered
K

5

6

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!

Kernite answered 23/10, 2011 at 6:11 Comment(0)
R
2

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.

Radiate answered 25/10, 2011 at 3:18 Comment(1)
Thanks! That did it. I dumped /.emacs.d/ and reinstalled again (before I just deleted the folders in /.emacs.d/elpa/). Then I only reinstalled the clojure-mode package. Now works with M-x clojure-jack-in. I guess it had something to do with the slime or slime-repl packages I was downloading. Also still using swank-clojure 1.3.3 and it's working without slime packages so I will avoid 1.4.0-SNAPSHOT unless something else pops up.Kernite
D
2

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.

Diapophysis answered 30/7, 2012 at 19:39 Comment(1)
Tutorial updated to use nrepl.el in favor of SLIME and swank-clojure.Diapophysis
S
1

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.

Staves answered 23/10, 2011 at 6:17 Comment(6)
Changed to "1.2.1" in project.clj, ran lein deps, ls shows "1.2.1" in lib/dev/, lein swank, & M-x slime-connect gives the same error. Thanks for trying though I was just going with newer versions since I wasn't sure if emacs 24 would have problems with older versions.Kernite
Un install the plugin & try again.. You can refer the Known issues are in swank-clojure github account: github.com/technomancy/swank-clojureStaves
Uninstalled the plugin with lein plugin uninstall swank-clojure 1.3.3 (~/.lein/plugins is empty now), ran lein deps & lein swank in the project folder, M-x slime-connect and M-x clojure-jack-in still give the same errors. Something I noticed now is when running lein swank it gives: user=> Connection opened on local port 4005 #<ServerSocket ServerSocket[addr=localhost/127.0.0.1,port=0,localport=4005]> instead of the single line in the original postKernite
@Kernite : Correct! do M-x slime-connect after you get the above message!Staves
I did, but it still gives the same error messages in the original post. Do you think it might be something with the packages I downloaded from ELPA?Kernite
So, uninstall the emacs and other packages, I don't recommend installing the package through the lein plugin. Install manually.Staves
S
0

Try to do the following, which works for me with Emacs 24 on Ubuntu:

  1. Install Leiningen. Make sure the directory where you install lein is on the $PATH!
  2. Install swank-clojure plugin:

    lein plugin install swank-clojure 1.3.3

  3. Create a new project with lein new. Do not add swank-clojureto the :dev-dependencies. (You really only need one or the other, the plugin or the entry in :dev-dependencies.)

  4. 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 install lein in a location that's already on the $PATH. In a standard Ubuntu install, ~/bin should be on the $PATH.)

  5. Open a file from the project, e.g. project.clj, and run M-x clojure-jack-in. This should start the Swank server and connect the SLIME REPL to it.

Singhal answered 24/10, 2011 at 20:4 Comment(4)
Thanks, I think I'm closer but still not quite there. I followed your directions and started emacs with PATH=$PATH:/home/element8/.lein emacs-snapshot. Once in emacs I opened project.clj in /tmp/test-project, and tried M-x clojure-jack-in which gives in the minibuffer: starting swank... then Loading something quick, I couldn't read it all but it looked like slime in /.emacs.d/, then gives the same error Symbol's function definition is void: define-slime-contribKernite
I also tried copying ~/.lein into /bin and it gives the same error as above, think I'm going to try reinstalling emacs and get the packages again to make sure that isn't the problem.Kernite
reinstalled emacs, reinstalled the 4 packages i had(clojure-mode, slime, slime-repl, and paredit), there were some warnings when the packages compiled but they compiled, and running M-x clojure-jack-in with project.clj open gives the following messages: Starting swank server... Loading /home/element8/.emacs.d/swank/slime-c3230b2c.elc... error in process filter: eval-buffer: Symbol's function definition is void: define-slime-contrib error in process filter: Symbol's function definition is void: define-slime-contrib I think my problem is with the slime package in .emacs.d but I'm not sure.Kernite
looks like I was wrong, removed the slime and slime-repl packages from emacs and the same error occurs, looks like it's coming from /.emacs.d/swank/ which I think it's pulling from swank-clojure 1.3.3 installed in lein.Kernite
G
0

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.

Getup answered 29/3, 2012 at 3:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.