简体   繁体   中英

nrepl.el and leiningen 2 default namespace?

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 (Cc Ck) 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

  1. load up my core.clj file and jack-in ( Mx nrepl-jack-in )
  2. Cc Ck to load the buffer into the REPL
  3. type (show-shapefile) and be impressed at my cleverness

In 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:

  1. Is this the correct behavior that I'm seeing? (ie I'm just being lazy?)
  2. Is there a way to be dropped into this namespace (or conversely, tell me that this is a stupid idea)?

just a couple changes to your workflow:

  1. load up my core.clj file and jack-in ( Mx nrepl-jack-in)
  2. Cc Cl to load the file
  3. cc Mn to switch the repl to the namespace
  4. type (show-shapefile) and be impressed at my cleverness

step 2 compiles the file, which creates the namespace
step 3 is just shorter than switching to the repl and running in-ns

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM