简体   繁体   English

nrepl.el和leiningen 2默认命名空间?

[英]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. 让Emacs / Clojure环境启动并运行,我现在遇到了我不确定是正常的行为。 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. 特别是,当我启动一个nREPL并编译(Cc Ck)我的缓冲区时,我会被放到我的core.clj文件顶部定义的命名空间之外。 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. 我应该添加免责声明,我对Clojure和名称空间有点新,所以我对这一切的理解可能是模糊的。 I'm open to opinionated answers that show me a Better Way™. 我愿意接受那些能够让我看到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. 我的emacs环境是Cocoa Emacs 24,主要使用Melpa存储库中的emacs入门工具包进行设置,并通过包管理器添加了clojure和nrepl包。

My leiningen 2 project was set up using lein new test-clj . 我的leiningen 2项目是使用lein new test-clj

My project.clj : 我的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 : 我的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 ) 加载我的core.clj文件和jack-in( Mx nrepl-jack-in
  2. Cc Ck to load the buffer into the REPL Cc Ck将缓冲区加载到REPL中
  3. type (show-shapefile) and be impressed at my cleverness 输入(show-shapefile)并对我的聪明才智印象深刻

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) 实际上,我得到的错误看起来像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. 如果,从REPL我第一次输入(in-ns`test-clj.core),我就是金色的。 Also, if I type (test-clj.core/show-shapefile) I'm set. 另外,如果我输入(test-clj.core / show-shapefile)我就设置了。

When I load a REPL in Counterclockwise, I automagically get dropped into the test-clj.core namespace, which seems mighty convenient. 当我在逆时针加载REPL时,我会自动进入test-clj.core命名空间,这似乎很方便。

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) 加载我的core.clj文件和jack-in( Mx nrepl-jack-in)
  2. Cc Cl to load the file Cc Cl加载文件
  3. cc Mn to switch the repl to the namespace cc Mn将repl切换到命名空间
  4. type (show-shapefile) and be impressed at my cleverness 输入(show-shapefile)并对我的聪明才智印象深刻

step 2 compiles the file, which creates the namespace 第2步编译文件,创建命名空间
step 3 is just shorter than switching to the repl and running in-ns 步骤3比切换到repl并运行in-ns

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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