【问题标题】:leinigen repl with profileleinigen repl 与配置文件
【发布时间】:2014-04-15 14:09:57
【问题描述】:

这个问题是How does one pre-load a clojure file in the leiningen repl? 的后续问题。

我的~/.lein/profiles.clj 如下所示:

{  
  :user {:source-paths ["C:/Users/username/.lein/src"] }
}

我的~/.lein/src/user.clj 可能如下所示:

(ns user)

(println "user file loaded")  

当我在包含project.clj 的文件夹中运行lein repl 时,会执行user.clj 文件,但是当我从另一个文件夹运行lein repl 时,它不会加载我的用户配置文件。是否有解决方法或者这种行为是设计使然?事实上,我知道 Leinigen 确实在加载我的 profile.clj(即使没有 project.clj),因为里面还有其他东西(摘自优秀的 pimp my repl 文章)。 Leinigen 只是对我的附加源路径设置有问题。

与此相关的另一个问题是我需要为我的user.clj 文件指定文件夹的完整路径:"C:/Users/username/.lein/src"。当我将其更改为 "~/.lein/src" 时,leiningen 无法加载我的文件。

【问题讨论】:

  • 您是否在文档中看到任何建议源路径中的~ 应该有效?一般来说,波浪号扩展只适用于 Linux shell - 我不希望它在 Java 或 Windows 平台上工作。
  • 很好:将其替换为 {:source-paths [~(str (System/getProperty "user.home") "/.lein/src")]} 并且有效。但是我仍然无法从其中没有 project.clj 的文件夹中使用它。

标签: clojure leiningen


【解决方案1】:

听起来您只想为您的lein repl 会话加载一些代码。这是通过profiles.clj:repl-options:init 键完成的。如果你想以这种方式组织,你可以在initload-file 其他文件。

{:user 
  {:repl-options 
    {:init (load-file "path-to-file/user.clj")} 
     ...}} 

注意:如果您使用 Windows 样式的路径分隔符 /,则需要将它们转义 //

【讨论】:

  • 谢谢,正是我想要的。以下 sn-p 对我有用,包括加载相对于我的主目录的脚本: {:user {:repl-options {:init (load-file (str (System/getProperty "user.home") "/. lein/src/user.clj"))}}}
  • 啊,我在 Windows 上通过 Cygwin 工作,假设您也使用“~/”路径引用。
猜你喜欢
  • 2015-03-21
  • 1970-01-01
  • 1970-01-01
  • 2019-03-28
  • 2020-01-13
  • 1970-01-01
  • 2011-09-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多