简体   繁体   English

如何用Emacs nREPL选择/切换Leiningen配置文件?

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

I have a :dev profile set up in my leiningen project file. 我在我的leiningen项目文件中设置了:dev配置文件。 This defines an :init and :init-ns setting for my repl session. 这为我的repl会话定义了:init和:init-ns设置。 If I launch nrepl in emacs (Mx 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. 如果我在emacs(Mx nrepl-jack-in)中使用光标在我的project.clj中的:dev关键字上启动nrepl,则启动repl并使用:init和:init-ns设置。 If I have my cursor elsewhere, the initial namespace is different (a test ns, not user), and :init hasn't been evaluated. 如果我将光标放在其他位置,则初始命名空间不同(测试ns,而不是用户),并且:尚未评估init。

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? 此外,有没有办法在repl启动后更改配置文件?

Thanks 谢谢

Contrary to what commenter @user7610 said, there is no cider-jack-in-with-profile function in cider. 与评论者@ user7610所说的相反, cider-jack-in-with-profile中没有cider-jack-in-with-profile Cider pull-request #544 was a bit misleading in that regard. 苹果酒拉请求#544在这方面有点误导。

If you want cider to load your own special-snowflake profile do this in emacs: 如果您希望苹果酒加载您自己的special-snowflake配置文件,请在emacs中执行此操作:

  • Mx set-variable cider-lein-parameters to eg with-profile +my-special-snowflake repl :headless Mx set-variable cider-lein-parameters to eg with-profile +my-special-snowflake repl :headless

or to set the variable interactively (so you can see it's current value before changing it): 或以交互方式设置变量(因此您可以在更改之前查看它的当前值):

  • Ch, v cider-lein-parameters and then click or hit enter on "customize" and set it there to eg with-profile +my-special-snowflake repl :headless and apply it Ch, v cider-lein-parameters然后点击或点击“自定义”输入并将其设置为例如with-profile +my-special-snowflake repl :headless并应用它

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). 除了base配置文件(为了运行nrepl和苹果酒所需要的)之外,这将导致你的下一个cider-jack-in加载my-special-snowflake配置文件。

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) 测试CIDER 0.16.0(里加)

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 我只是在搜索相同的功能,并在clojure-emacs / nrepl.el中找到了这个未解决的问题“将参数添加到nrepl-jack-in以允许指定配置文件” https://github.com/clojure-emacs/nrepl。 EL /问题/ 327

it is still open 它仍然是开放的

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) . 我在我的计算机上尝试了Jiacai Liu的函数作者(2019-04-13的GNU Emacs 26.2(build 1,x86_64-apple-darwin18.2.0,NS appkit-1671.20 Version 10.14.3(Build 18D109))。 I get a error is: 我得到一个错误是:

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

And then, I try to elisp function as: 然后,我尝试elisp功能:

(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! 谢谢Jiacai Liu!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM