How do I choose/switch Leiningen profiles with Emacs nREPL?

clojure, emacs, leiningen, nrepl

Solution

Contrary to what commenter @user7610 said, there is no `cider-jack-in-with-profile` function in cider. Cider pull-request #544 was a bit misleading in that regard.

If you want cider to load your own `special-snowflake` profile do this in emacs:

- `M-x set-variable cider-lein-parameters` to e.g. `with-profile +my-special-snowflake repl :headless`

or to set the variable interactively (so you can see it's current value before changing it):

- `C-h, v cider-lein-parameters` and then click or hit enter on "customize" and set it there to e.g. `with-profile +my-special-snowflake repl :headless` and apply it

That'll cause your next `cider-jack-in` to load the `my-special-snowflake` profile in addition to the `base` profile (which is needed in order to run the nrepl and hence cider).

Problem

I have a :dev profile set up in my leiningen project file. This defines an :init and :init-ns setting for my repl session. If I launch nrepl in emacs (M-x nrepl-jack-in) with the cursor over the :dev keyword in my project.clj, the repl launches and the :init and :init-ns settings are used. If I have my cursor elsewhere, the initial namespace is different (a test ns, not user), and :init hasn't been evaluated. I'm guessing it's a feature of some sort, (I'm more inclined to think it's random buggy behaviour now) but can anyone explain it or point me at the docs that do so? Also, is there any way to change the profile once the repl's been launched? Thanks

Original source