Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 (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

  1. load up my core.clj file and jack-in (M-x nrepl-jack-in)
  2. C-c C-k 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? (i.e. 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)?
like image 760
Peter Avatar asked Oct 19 '12 22:10

Peter


1 Answers

just a couple changes to your workflow:

  1. load up my core.clj file and jack-in (M-x nrepl-jack-in)
  2. C-c C-l to load the file
  3. c-c M-n 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

like image 159
Arthur Ulfeldt Avatar answered Sep 21 '22 06:09

Arthur Ulfeldt