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

4

7

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

Christchurch answered 18/8, 2013 at 22:28 Comment(2)
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)Heckle
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...Christchurch
S
15

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

Soul answered 19/3, 2015 at 14:7 Comment(0)
H
2

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)

Halation answered 28/3, 2018 at 2:50 Comment(1)
Slightly more idiomatic: take profile as an argument and then do (interactive "sEnter profile name: ").Virgil
R
1

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

Resurge answered 15/10, 2013 at 22:22 Comment(1)
it became cider-jack-in-with-profile, available since Q1 2014Valuation
M
0

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!

Mader answered 22/5, 2019 at 7:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.