Clojure.repl namespace lost after clojure.tools.namespace refresh-all
I'm not sure if this was expected or an error, but after startup (clojure.tools.namespace.repl/refresh-all)
the namespace clojure.repl
is lost.
nREPL server started on port 61579 on host 127.0.0.1 nrepl://127.0.0.1:61579 REPL-y 0.3.5, nREPL 0.2.7 Clojure 1.6.0 testbed.core=> (doc map) ------------------------- clojure.core/map ([f coll] [f c1 c2] [f c1 c2 c3] [f c1 c2 c3 & colls]) Returns a lazy... nil testbed.core=> (require 'clojure.tools.namespace.repl) nil testbed.core=> (clojure.tools.namespace.repl/refresh-all) :reloading (testbed.core testbed.core-test) :ok testbed.core=> (doc map) CompilerException java.lang.RuntimeException: Unable to resolve symbol: doc in this context, compiling:(/private/var/folders/xs/jbvb_r6j07q8xtclwlcbm21h0000gn/T/form-init6764593924445976503.clj:1:1) testbed.core=>
My .clj project is very simple:
(defproject testbed "0.1.0-SNAPSHOT" :description "FIXME: write description" :url "http://example.com/FIXME" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[org.clojure/clojure "1.6.0"]] :main ^:skip-aot testbed.core :target-path "target/%s" :profiles {:uberjar {:aot :all} :dev {:dependencies [[org.clojure/tools.namespace "0.2.10"]]}})
Is there an easy way to avoid this? In particular, while running Emacs / CIDER?
source to share
I remember this problem. Even though it's been around for a while, I am reminded of this by creating my lein project to start replacing in the namespace user
and importing other namespaces instead of running in the project's namespace (defined :main
).
So, I added :repl-options {:init-ns user}
to mine project.clj
and also created a project user.clj
- which makes sure the features clojure.repl
I need are always available - as described in the Stuart Sierra post "My Clojure Workflow, Reloaded"
Session:
user=> (doc +)
-------------------------
clojure.core/+
([] [x] [x y] [x y & more])
Returns the sum of nums. (+) returns 0. Does not auto-promote
longs, will throw on overflow. See also: +'
nil
user=> (clojure.tools.namespace.repl/refresh-all)
(...namespaces...)
user=> (doc +)
-------------------------
clojure.core/+
([] [x] [x y] [x y & more])
Returns the sum of nums. (+) returns 0. Does not auto-promote
longs, will throw on overflow. See also: +'
nil
This is a workaround, not a real fix or explanation for the behavior. Another approach might be to ensure
source to share
clojure.tools.namespace.repl/refresh-all
works by destroying the current version of namespace memory before loading a new one. Since the function is doc
inserted by the REPL at startup and is not defined in the source file, it is lost on reboot.
You can use disable-unload functions! and disable reboot! c clojure.tools.namespace.repl
to prevent updates from automatically deleting / reloading namespaces. nREPL inserts helper functions such as doc
into the original namespace, which is your application's main namespace by default. You can ensure that these functions are inserted elsewhere by setting an alternate initial namespace in the Leiningen profile.
I also recommend creating an actual source file for the namespace that contains helper functions for use in the REPL. You can find a description of how to do this in one of my other answers .
An example of setting up a user profile can be found on my Github .
source to share