Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clojure.repl namespace lost after clojure.tools.namespace refresh-all

Tags:

emacs

clojure

I'm not sure if this is expected or a bug, but after running (clojure.tools.namespace.repl/refresh-all) the clojure.repl namespace 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 project.clj 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 a simple way to avoid this? Particular while running Emacs/CIDER?

like image 244
drt Avatar asked Feb 11 '23 06:02

drt


1 Answers

I remember having this issue. Although it's been a while, I recall getting around this by setting up my lein project to start the repl in namespace user and import the other namespaces - rather than starting out in the project namespace (defined by :main).

So I added :repl-options {:init-ns user} to my project.clj and also created a project user.clj - that ensures that clojure.repl functions I need are always available - as described in Stuart Sierra's 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 work-around and not a real fix or explanation of the behavior. Another approach could be to ensure

like image 150
noahlz Avatar answered Feb 14 '23 08:02

noahlz