【问题标题】:How do I choose/switch Leiningen profiles with Emacs nREPL?如何使用 Emacs nREPL 选择/切换 Leiningen 配置文件?
【发布时间】:2013-08-20 16:29:50
【问题描述】:

我在我的 leiningen 项目文件中设置了一个 :dev 配置文件。这为我的 repl 会话定义了一个 :init 和 :init-ns 设置。如果我在 emacs (M-x nrepl-jack-in) 中启动 nrepl,并将光标悬停在 project.clj 中的 :dev 关键字上,repl 将启动并使用 :init 和 :init-ns 设置。如果我将光标放在别处,则初始命名空间不同(测试 ns,而不是用户),并且 :init 尚未被评估。

我猜这是某种功能,(我现在更倾向于认为这是随机的错误行为)但是谁能解释它或指向我这样做的文档?另外,repl 启动后有什么方法可以更改配置文件吗?

谢谢

【问题讨论】:

  • 我查看了 nrepl.el 的源代码,在任何地方都看不到运行 lein with-profiles 的任何参考 - 而且我似乎无法根据位置重现配置文件的行为光标是 - 你确定这是怎么回事?我认为 nrepl 可能只是使用 :default 配置文件,它是 [:base :system :user :provided :dev] (github.com/technomancy/leiningen/blob/master/doc/PROFILES.md) 的组合
  • 我首先怀疑是故意的行为,但它似乎不一致 - 现在更像是一个错误。该项目同时具有 clj 和 cljs 文件,因此可能会感到困惑...

标签: emacs clojure leiningen nrepl


【解决方案1】:

与评论者@user7610 所说的相反,苹果酒中没有cider-jack-in-with-profile 功能。苹果酒pull-request #544 在这方面有点误导。

如果您希望 cider 加载您自己的 special-snowflake 配置文件,请在 emacs 中执行此操作:

  • M-x set-variable cider-lein-parameters 例如with-profile +my-special-snowflake repl :headless

或以交互方式设置变量(这样您就可以在更改之前看到它的当前值):

  • C-h, v cider-lein-parameters 然后在“自定义”上单击或按回车键并将其设置为例如with-profile +my-special-snowflake repl :headless 并应用它

这将导致您的下一个 cider-jack-in 加载 my-special-snowflake 配置文件以及 base 配置文件(这是运行 nrepl 和苹果酒所必需的)。

【讨论】:

    【解决方案2】:

    试试这个:

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

    在 CIDER 0.16.0(里加)上测试

    【讨论】:

    • 更习惯用法:将profile 作为参数,然后使用(interactive "sEnter profile name: ")
    【解决方案3】:

    我只是在搜索相同的功能,并在 clojure-emacs/nrepl.el “向 nrepl-jack-in 添加参数以允许配置文件规范”https://github.com/clojure-emacs/nrepl.el/issues/327 中发现了这个未解决的问题

    它仍然开放

    【讨论】:

    • 它变成了cider-jack-in-with-profile,从 2014 年第一季度开始提供
    【解决方案4】:

    我在我的计算机中尝试Jiacai Liu 的函数作者(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 ) .我得到的错误是:

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

    然后,我尝试将函数省略为:

    (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 '())))
    

    现在可以了。谢谢刘家菜!

    【讨论】:

      猜你喜欢
      • 2015-05-22
      • 1970-01-01
      • 2011-12-13
      • 2022-07-23
      • 1970-01-01
      • 1970-01-01
      • 2011-06-17
      • 1970-01-01
      相关资源
      最近更新 更多