qrest
qrest

Reputation: 31

Clojure 1.2 is released! How to get swank-clojure to use this?

I just set up a new emacs installation, installed ELPA and installed swank-clojure with using ELPA. Although Clojure 1.2 is released, when I hit "M-x slime", it still downloaded Clojure 1.1 for me instead of 1.2

How do I get it to use 1.2 now that it's available? Do I have to do it manually? Do I have to wait for slime/swank to be updated to use 1.2?

Update: Thanks for the recommendations for using leiningen, but what I'm after is for emacs to just launch a REPL itself. Is this problem happening because the swank-clojure package in ELPA is not being updated?

Upvotes: 3

Views: 1443

Answers (4)

Jaskirat
Jaskirat

Reputation: 1094

You just need to set the swank-clojure-classpath variable before you hit M-x slime

Say if you have the clojure.jar, clojure-contrib.jar and swank-clojure.jar under c:\jars

In the scratch buffer paste this

(setq swank-clojure-classpath '("c:/jars/clojure.jar" "c:/jars/cloure-contrib.jar" 
"c:/jars/swank-clojure.jar"))

Hit C-x C-e and the M-x slime , that should do it.

For details checkout

https://github.com/jochu/swank-clojure/blob/master/swank-clojure.el#L32-34

http://en.wikibooks.org/wiki/Clojure_Programming/FAQ#Where_does_swank-clojure_.28SLIME.29_look_for_Clojure.27s_jars.3F

Upvotes: 0

user61051
user61051

Reputation:

With Leiningen 1.3, it's easy to create a standalone swank session:

$ lein install swank-clojure 1.3.0-SNAPSHOT
$ ~/.lein/bin/swank-clojure

You can add ~/.lein/bin to your $PATH to make this easier.

Then inside Emacs:

M-x slime-connect

Launching swank from inside Emacs can be done with M-x lein-swank if you are inside a project directory. However, auto-download and install of Clojure and other dependencies via swank-clojure.el is error-prone and deprecated.

Upvotes: 5

Michał Marczyk
Michał Marczyk

Reputation: 84331

I believe that with the sort of setup that you describe, M-x slime will put everything in ~/.clojure and ~/.swank-clojure on the classpath. You can customise this by setting the swank-clojure-classpath variable (I have it customised to use ~/.clojure only; that's where I put the basic set of jars useful for launching one-off experimental REPLs.

As soon as you need more stuff on the classpath, the above is inadequate. There are two options for managing those more complex cases:

Option 1: launch Swank, then connect

The most straightforward approach is to use Leiningen. Put this in your project.clj:

(defproject repl-base "1.0.0-SNAPSHOT"
  :description "A project to start Swank in."
  :dependencies [[org.clojure/clojure "1.2.0"]
                 [org.clojure/clojure-contrib "1.2.0"]]
  :dev-dependencies [[swank-clojure "1.2.1"]])

Then use lein swank in your project's directory to start a swank server and use M-x slime-connect to connect to it from within Emacs.

As another possibility, David Edgar Liebke's cljr will apparently launch stand-alone Swank instances for you; consult the README for details.

Option 2: launch Swank from within Emacs

Now, to be entirely honest, I tend to start Swank from within Emacs myself -- it's maybe a bit trickier to setup (and thus possibly not advisable in the beginning), but quite convenient later on. See my answer to an older question for one version of a function I use to launch Clojure-specific Swank instances complete with proper classpath configuration for Leiningen-style projects.

Upvotes: 3

Peter Tillemans
Peter Tillemans

Reputation: 35331

I use leiningen to connect emacs slime to the clojure instance. In a project you always end up with a couple of dependencies, which leiningen nicely places on the classpath.

It uses a small clojure file to describe the dependencies, e.g. :

(defproject myprojecy "0.1.0-SNAPSHOT"
   :description "A project."
   :dependencies [[org.clojure/clojure "1.2.0-beta1"]
                 [org.clojure/clojure-contrib "1.2.0-beta1"]]
   :dev-dependencies [[swank-clojure "1.2.1"]])

You can see that changing versions is just a couple of keystrokes in an editor. Leiningen downloads the dependencies from the 'net which keeps the projects really smal and fast to version control.

running lein swank starts the program and the repl in swank :

ptimac:cljhack pti$ lein swank
user=> Connection opened on local port  4005
#<ServerSocket ServerSocket[addr=localhost/127.0.0.1,port=0,localport=4005]>

you can now connect in emacs using M-x slime-connect and accept the defaults.

Upvotes: 1

Related Questions