7
votes

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

4
I've had a look through nrepl.el's source code and can't see any reference to running lein with-profiles anywhere - also I can't seem to reproduce the behaviour the profile depending on where the cursor is - are you sure this is what's happening? I think nrepl is probably just using the :default profile which is a composite of [:base :system :user :provided :dev] (github.com/technomancy/leiningen/blob/master/doc/PROFILES.md)Daniel Neal
I first suspected deliberate behaviour, but it seems inconsistent - more like a bug now. The project has both clj and cljs files, so maybe it's getting confused...Graham MacDonald

4 Answers

15
votes

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).

2
votes

Try this:

(defun start-cider-repl-with-profile ()
  (interactive)
  (letrec ((profile (read-string "Enter profile name: "))
           (lein-params (concat "with-profile +" profile " repl :headless")))
    (message "lein-params set to: %s" lein-params)
    (set-variable 'cider-lein-parameters lein-params)
    (cider-jack-in)))

Test on CIDER 0.16.0 (Riga)

1
votes

I'm just searching the same feature and found this open issue in clojure-emacs/nrepl.el "Add argument to nrepl-jack-in to allow specification of profiles" https://github.com/clojure-emacs/nrepl.el/issues/327

it is still open

0
votes

I try the function author by Jiacai Liu in my computer(GNU Emacs 26.2 (build 1, x86_64-apple-darwin18.2.0, NS appkit-1671.20 Version 10.14.3 (Build 18D109)) of 2019-04-13) . I get a error is:

eval-region: Wrong number of arguments: (1 . 1), 0

And then, I try to elisp function as:

(defun start-cider-repl-with-profile ()
  (interactive)
  (letrec ((profile (read-string "Enter profile name: "))
           (lein-params (concat "with-profile +" profile " repl :headless")))
    (message "lein-params set to: %s" lein-params)
    (set-variable 'cider-lein-parameters lein-params)
    (cider-jack-in '())))

Now it work. Thanks for Jiacai Liu!