Getting an Emacs / Clojure environment up and running, I'm now running into behavior that I'm not sure is normal. In particular, when I start an nREPL and compile (C-c C-k) my buffer, I get dropped into something other than the namespace defined at the top of my core.clj file. I should add the disclaimer that I'm a bit new to Clojure and namespaces, and so my understanding of all this might be murky. I'm open to opinionated answers that show me a Better Way™.
First, about my setup:
My emacs environment is Cocoa Emacs 24, set up mostly with the emacs starter kit from the Melpa repository, with the clojure and nrepl packages added via the package manager.
My leiningen 2 project was set up using lein new test-clj
.
My project.clj:
(defproject test-clj "0.1.0-SNAPSHOT"
:description "A geospatial test app example mostly ripped off from http://datamangling.com/blog/2010/05/26/geotools-quickstart-in-clojure/"
:repositories {"osgeo-geotools" "http://download.osgeo.org/webdav/geotools"}
:url "FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.4.0"]
[org.geotools/gt-main "8.2"]
[org.geotools/gt-shapefile "8.2"]
[org.geotools/gt-epsg-hsql "8.2"]
[org.geotools/gt-swing "8.2"]])
My core.clj:
(ns test-clj.core
(:import [org.geotools.data CachingFeatureSource FeatureSource FileDataStore FileDataStoreFinder])
(:import [org.geotools.map DefaultMapContext MapContext])
(:import [org.geotools.swing JMapFrame])
(:import [org.geotools.swing.data JFileDataStoreChooser]))
(defn show-shapefile
"Prompts the user for a shapefile and displays its content"
[]
(if-let [shapefile (JFileDataStoreChooser/showOpenFile "shp" nil)]
(let [fs (.getFeatureSource (FileDataStoreFinder/getDataStore shapefile))]
(doto (DefaultMapContext.)
(.setTitle "Quickstart")
(.addLayer fs nil)
(JMapFrame/showMap)))))
I think I should be able to
M-x nrepl-jack-in
)C-c C-k
to load the buffer into the REPLIn actuality, I get an error that looks like clojure.lang.Compiler$CompilerException: java.lang.RuntimeException: Unable to resolve symbol: show-shapefile in this context, compiling:(NO_SOURCE_PATH:1)
If, from the REPL I first type (in-ns `test-clj.core), I'm golden. Also, if I type (test-clj.core/show-shapefile) I'm set.
When I load a REPL in Counterclockwise, I automagically get dropped into the test-clj.core namespace, which seems mighty convenient.
My question then is two-fold:
just a couple changes to your workflow:
step 2 compiles the file, which creates the namespace
step 3 is just shorter than switching to the repl and running in-ns
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With