Where to put nREPL init options?

1,069 views
Skip to first unread message

James Thornton

unread,
Oct 7, 2012, 11:53:03 PM10/7/12
to clojur...@googlegroups.com
I'm working with gaeshi (https://github.com/slagyr/gaeshi), one of the new Google App Engine libraries, and I'm using nREPL in Emacs. 

The default gaeshi project.clj sets up the App Engine environment in the REPL via:

  :repl-options {:init (do (use 'gaeshi.tsukuri.environment) (setup-environment "thornton-development"))}

...but this doesn't set the nREPL environment so that it's set up when programming interactively in core.clj, for example.

What's the proper way of setting this when you jack in to nREPL?

Do you create an nREPL middleware or handler, and if so, where is the documentation for doing that?

Thanks.

- James



Chas Emerick

unread,
Oct 8, 2012, 12:56:03 PM10/8/12
to clojur...@googlegroups.com
Is your environment set up properly if you start the REPL on the command line using `lein repl`?  I'm guessing it is.

IIRC, the :init option is not used when the Leiningen/nREPL server is started in "headless" mode, which is what nrepl.el does (this just starts the server, and skips the usage of reply to run a terminal-based nREPL client connected to the new server).  I personally think that :init probably should be included in the bootstrapping of all REPLs started from `lein`, including headless ones.  Filing an issue with Leiningen would be your next step if you agree.

A temporary workaround might be to use whatever hooks nrepl.el provides to send whatever init forms you want to newly-started nREPL servers.

nREPL middlewares and handlers aren't really relevant here.

Cheers,

- Chas

Sam Aaron

unread,
Oct 8, 2012, 1:19:52 PM10/8/12
to clojur...@googlegroups.com

On 8 Oct 2012, at 17:56, Chas Emerick <ch...@cemerick.com> wrote:

> I personally think that :init probably should be included in the bootstrapping of all REPLs started from `lein`, including headless ones. Filing an issue with Leiningen would be your next step if you agree.

If I'm correct in assuming that this would allow you to boot an nREPL server with a specified port without starting reply, then I totally agree.

Sam

---
http://sam.aaron.name

Chas Emerick

unread,
Oct 8, 2012, 1:38:32 PM10/8/12
to clojur...@googlegroups.com
You can do that already with this in project.clj:

{:repl-options {:port XXXX}}

`lein repl :headless` will start nREPL on port XXXX.

The :init option would just give you the ability to add code that should always be evaluated after the nREPL server is up.

- Chas

Colin Jones

unread,
Oct 8, 2012, 1:46:26 PM10/8/12
to clojur...@googlegroups.com
I believe this is tracked here:
https://github.com/technomancy/leiningen/issues/788
--
Colin Jones
@trptcolin

Phil Hagelberg

unread,
Oct 8, 2012, 6:00:01 PM10/8/12
to clojur...@googlegroups.com
Colin Jones <trpt...@gmail.com> writes:

> I believe this is tracked here:
> https://github.com/technomancy/leiningen/issues/788

Would love to have some help fixing this as it's just an oversight. I
don't think it would be difficult at all.

-Phil

Tim King

unread,
Oct 11, 2012, 10:40:35 AM10/11/12
to clojur...@googlegroups.com
I just submitted a pull request that should fix this.

Cheers,
Tim

Sam Aaron

unread,
Oct 11, 2012, 4:15:12 PM10/11/12
to clojur...@googlegroups.com

On 8 Oct 2012, at 20:38, Chas Emerick <ch...@cemerick.com> wrote:

> You can do that already with this in project.clj:
>
> {:repl-options {:port XXXX}}
>
> `lein repl :headless` will start nREPL on port XXXX.
>

Awesome. Is there a way to make this global for all lein projects?

Sam

---
http://sam.aaron.name

Chas Emerick

unread,
Oct 11, 2012, 4:43:22 PM10/11/12
to clojur...@googlegroups.com
On Oct 11, 2012, at 4:15 PM, Sam Aaron wrote:

>
> On 8 Oct 2012, at 20:38, Chas Emerick <ch...@cemerick.com> wrote:
>
>> You can do that already with this in project.clj:
>>
>> {:repl-options {:port XXXX}}
>>
>> `lein repl :headless` will start nREPL on port XXXX.
>>
>
> Awesome. Is there a way to make this global for all lein projects?

Sure, just drop the above into e.g. the :user profile in ~/.lein/profiles.clj:

{:user {:repl-options {:port XXXX}}}

Though, if you do this, you'll only be able to run one REPL at a time. A better solution might be to use an alias to turn on a profile that contains the preferred port and run a new REPL; this will allow you to run a REPL on the "standard" port easily while still being able to spin up other REPLs freely:

{:standard-repl {:repl-options {:port XXXX}}
:user {:aliases {"stdrepl" ["with-profile" "dev,user,standard-repl" "repl"]}}}

...then:

$ lein stdrepl

That'll only work if there's a project.clj in pwd, but hopefully that'll work for you. :-)

- Chas

Jim Crossley

unread,
Oct 11, 2012, 4:50:33 PM10/11/12
to clojur...@googlegroups.com

Another option is to set port to 0 in the :user profile, letting the OS choose an available one, which lein will display on stdout iirc.

Jim

Chas Emerick

unread,
Oct 12, 2012, 11:53:12 AM10/12/12
to clojur...@googlegroups.com
That is the default in Leiningen as-is, without any profile configuration.

- Chas
Reply all
Reply to author
Forward
0 new messages