Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 545
Graham MacDonald Avatar asked Aug 18 '13 22:08

Graham MacDonald


2 Answers

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

like image 94
Bill Burcham Avatar answered Sep 28 '22 02:09

Bill Burcham


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)

like image 29
Jiacai Liu Avatar answered Sep 28 '22 02:09

Jiacai Liu