when I start swank through leiningen it accepts the next slime connection and off I go. I would really like to have several emacs instances connect to the same swank instance. Can I do this? can I do this through leiningen?
Well, you can start your first SLIME normally, then (require 'swank.swank)
(or maybe it's required by default... not sure), do (swank.swank/start-repl port)
with port
replaced by some port number and you can connect a second instance of SLIME to that newly created REPL.
I've done it just now, with one Emacs connecting to a REPL started with lein swank
, (swank.swank/start-repl 4006)
in the first Emacs, M-x slime-connect in the second Emacs (providing 4006 as the port number), then I could do this:
; first Emacs
(def x 5)
; second Emacs
x ; evaluates to 5
(def y 1234)
; first Emacs
y ; evaluates to 1234
Cool, no? :-)
Update: Oh, BTW -- (swank.swank/start-repl)
starts the new REPL in the background and does not block the REPL you use to execute it. The return value is nil
, so I'm not sure how to kill the new REPL...
(Update 2: Removed something I'm no longer sure about.)
Update 3: While the above method is perfectly general in that it makes it possible to connect an extra client regardless of how the original Swank instance has been started, it might be more convenient to start Swank with the command
lein swank 4005 "localhost" :dont-close true
The port and host name arguments must mentioned explicitly if :dont-close true
is to be passed. 4005
and "localhost"
are the default values.
This will make it possible to disconnect from Swank and reconnect later, but also to connect a number of clients simultaneously.
(I just noticed that this is possible while answering this new question on how to enable reconnections to Leiningen-started Swank; it suddenly occurred to me to check if :dont-close
would also cause simultaneous connections to be accepted -- and it does.)