Welcome! Please see the About page for a little more info on how this works.

0 votes
in Clojure by

I'm experimenting using Clojure's socket repl in some project that use lein.

I added this my lein profile:

:jvm-opts ["-Dclojure.server.repl={:port 0 :accept clojure.core.server/repl}"]

I'm using port 0 because if I use some hardcoded value, I won't be able to run multiple socket repls, as they would point to the same port.

This works, but it's still a bit painful because I need to manually get the port number (see the code below) and use that for connecting with Emacs.

(.getLocalPort (get-in @#'clojure.core.server/servers ["repl" :socket]))

I'm wondering if there's any way of automating this.

1 Answer

0 votes
by
selected by
 
Best answer

My solution -- for the Clojure CLI -- is to have an alias that runs my own "startup" code in a dev.clj file. It explicitly starts the Socket REPL and reports the port used. I haven't used lein for years but I seem to recall you can tell Leiningen to run a particular bit of code at startup, so you could put your .getLocalPort call into such code I think.

Also, Clojure itself will load user.clj if it is directly on the classpath so that's another avenue for reporting the selected port.

by
Thanks, Sean.
...