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

Emacs nrepl.el和leiningen 2默认名称空间?,emacs,clojure,leiningen,Emacs,Clojure,Leiningen,在启动并运行Emacs/Clojure环境时,我现在遇到了我不确定是否正常的行为。特别是,当我启动一个nREPL并编译(C-C-k)我的缓冲区时,我会被放到core.clj文件顶部定义的名称空间之外的其他地方。我应该加上免责声明,我对Clojure和名称空间有点陌生,因此我对这一切的理解可能是模糊的。我愿意接受那些给我提供更好方法的固执己见的答案™. 首先,关于我的设置: 我的emacs环境是Cocoa emacs 24,主要使用Melpa存储库中的emacs初学者工具包进行设置,并通过pack

在启动并运行Emacs/Clojure环境时,我现在遇到了我不确定是否正常的行为。特别是,当我启动一个nREPL并编译(C-C-k)我的缓冲区时,我会被放到core.clj文件顶部定义的名称空间之外的其他地方。我应该加上免责声明,我对Clojure和名称空间有点陌生,因此我对这一切的理解可能是模糊的。我愿意接受那些给我提供更好方法的固执己见的答案™.

首先,关于我的设置:

我的emacs环境是Cocoa emacs 24,主要使用Melpa存储库中的emacs初学者工具包进行设置,并通过package manager添加clojure和nrepl包

我的leiningen 2项目是使用
lein new test clj
建立的

我的项目。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"]])
(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)))))
我的核心.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"]])
(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)))))
我想我应该可以

  • 加载my core.clj文件并插入(
    M-x nrepl插入
  • C-C-k
    将缓冲区加载到REPL
  • 输入(显示形状文件)并对我的聪明印象深刻
  • 实际上,我得到一个类似于
    clojure.lang.Compiler$CompilerException:java.lang.RuntimeException:无法解析符号:在此上下文中显示shapefile,编译:(无源代码\u路径:1)

    如果,从REPL I第一个类型(在ns`test clj.core中),我是golden。另外,如果我键入(test clj.core/show shapefile),我就设置好了

    当我逆时针加载REPL时,我自动地被放入test-clj.core名称空间,这看起来非常方便

    那么,我的问题有两个:

  • 这是我看到的正确行为吗?(也就是说,我只是在偷懒?)
  • 有没有一种方法可以放到这个名称空间中(或者相反,告诉我这是一个愚蠢的想法)

  • 只需对您的工作流程进行几处更改:

  • 加载my core.clj文件并插入(M-x nrepl插入)
  • C-C-l加载文件
  • c-cm-n将repl切换到命名空间
  • 输入(显示形状文件)并对我的聪明印象深刻
  • 步骤2编译文件,创建名称空间

    步骤3比切换到repl并在ns中运行

    要短,太棒了!看起来我还可以继续用
    C-C-k
    加载当前缓冲区。
    C-cmn
    似乎是一种魔力。旁白:如何在StackOverflow注释中获得格式良好的emacs键盘快捷键?Ctrlaltdel看起来这可能与教程中的一个错误有关,该错误指出命名空间切换受
    C-C
    C-n
    影响,而不是正确的
    C-C
    M-n