使用 leiningen REPL 时,有没有办法使文件或 ns 在文件保存时自动重新加载到 repl 中。目前,我通过在 repl 中输入以下内容来重新加载 ns -(use 'sample.ns :reload-all)
.
但是我可以让它在文件保存时自动重新加载吗?
您可以轻松地重用来自的代码duct https://github.com/duct-framework/core/blob/3dc4908902cff81323bee89eaef94012194cbd24/src/duct/core/repl.clj#L31框架。
你只需要hawk https://github.com/wkf/hawk文件观察者。
它的样子如下:
(defn- clojure-file? [_ {:keys [file]}]
(re-matches #"[^.].*(\.clj|\.edn)$" (.getName file)))
(defn- auto-reset-handler [ctx event]
(binding [*ns* *ns*]
(clojure.tools.namespace.repl/refresh)
ctx))
(defn auto-reset
"Automatically reset the system when a Clojure or edn file is changed in
`src` or `resources`."
[]
(hawk.core/watch! [{:paths ["src/" "resources/" "dev/src/" "dev/resources/"]
:filter clojure-file?
:handler auto-reset-handler}]))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)