简体   繁体   English

使用leiningen为clojure设置emacs / slime / swank

[英]Setting up emacs/slime/swank for clojure with leiningen

Short version: errors when running Mx slime-connect or Mx clojure-jack-in when using lein swank to start the swank server. 短版本:使用lein swank启动swank服务器时运行Mx slime-connect或Mx clojure-jack-in时出错。

I'm using emacs 24.0.50.1 on Ubuntu 10.10. 我在Ubuntu 10.10上使用emacs 24.0.50.1。 I've installed the following packages in emacs from ELPA: clojure-mode, paredit, slime, slime-repl 我在ELPA的emacs中安装了以下软件包:clojure-mode,paredit,slime,slime-repl

I installed leiningen from github & added it to the classpath, then ran lein plugin install swank-clojure 1.3.3 . 我从github安装了leiningen并将其添加到类路径中,然后运行lein plugin install swank-clojure 1.3.3 After that I created a new directory ~/tmp/, cd into it and ran: lein new test-project which seemed to setup everything ok. 之后我创建了一个新的目录〜/ tmp /,cd进入它并运行: lein new test-project ,似乎设置一切正常。 Then I opened up /tmp/new-project/project.clj in emacs and changed it to: 然后我在emacs中打开了/tmp/new-project/project.clj并将其更改为:

(defproject test-project "1.0.0-SNAPSHOT"
:description "Test Project"
:dependencies [[org.clojure/clojure "1.2.1"]
               [org.clojure/clojure-contrib "1.2.0"]]
:dev-dependencies [[swank-clojure "1.3.3"]])

After that I went back in the /tmp/new-project folder and ran lein deps then lein swank to download the dependencies and start the swank server which gives the output: 之后我回到/ tmp / new-project文件夹并运行lein deps然后lein swank下载依赖项并启动lein swank服务器,它提供输出:

Connection opened on local port 4005.

Back in emacs is where I'm having the problem of getting it to connect to the swank server. 回到emacs是我遇到连接到swank服务器的问题。 I've tried opening the core.clj file and running Mx slime-connect which gives the error: 我试过打开core.clj文件并运行Mx slime-connect ,它给出了错误:

Symbol's function definition is void: define-slime-contrib

Which makes me think it either doesn't see the swank server running or there's some config that needs to be done for it to see the server. 这让我觉得它或者看不到swank服务器正在运行,或者有一些配置需要为它查看服务器。 I also tried (with the same file open and with project.clj open) Mx clojure-jack-in which I assume tries to start the clojure REPL in the project folder but that gives the following: 我也尝试过(打开同一个文件并打开project.clj) Mx clojure-jack-in我假设尝试在项目文件夹中启动clojure REPL但是它给出了以下内容:

Debugger entered--Lisp error: (error "Could not start swank server: sh: lein: not found
")
signal(error ("Could not start swank server: sh: lein: not found\n"))
error("Could not start swank server: %s" "sh: lein: not found\n")
clojure-jack-in-sentinel(#<process swank> "exited abnormally with code 127\n")

I was following directions from http://matthias-schneider.org/docs/clojure-setup/ for the emacs packages and lein setup, then started following the Test Configuration instructions from http://riddell.us/ClojureSwankLeiningenWithEmacsOnLinux.html once I had problems getting Mx slime-connect to open a REPL. 我正在按照http://matthias-schneider.org/docs/clojure-setup/关于emacs包和lein设置的指示,然后开始按照http://riddell.us/ClojureSwankLeiningenWithEmacsOnLinux.html上的测试配置说明进行操作有问题让Mx slime-connect打开一个REPL。

Update : 更新

deleted ~/tmp/test-project, uninstalled emacs and /.emacs.d/elpa/ packages, reinstalled emacs, reinstalled clojure-mode and paredit packages, copied ~/.lein into /bin to make sure of no path issues (wasn't sure if /.lein or /.lein/bin needed to be in the path). 删除〜/ tmp / test-project,卸载emacs和/.emacs.d/elpa/包,重新安装emacs,重新安装clojure-mode和paredit包,将〜/ .lein复制到/ bin以确保没有路径问题(wasn如果/.lein或/.lein/bin需要在路径中,请确保。 Ran /.lein/bin/swank-clojure and then opened emacs, opened the project.clj, and tried Mx slime-connect , which now asks me for a host (local default), port (4005 default), says connecting to swank, gives a message about swank and slime versions differing (y or n) y, then the minibuffers gives error in process filter: Lisp connection closed unexpectedly . Ran /.lein/bin/swank-clojure然后打开emacs,打开了project.clj,并尝试了Mx slime-connect ,现在要求我输入主机(本地默认),端口(默认为4005),连接到swank ,给出一个关于swank和slime版本不同(y或n)y的消息,然后minibuffers error in process filter: Lisp connection closed unexpectedly给出error in process filter: Lisp connection closed unexpectedly In the terminal where I ran /.lein/bin/swank-clojure the following java error pops up: 在我运行/.lein/bin/swank-clojure的终端中弹出以下java错误:

exception in read loop
java.lang.NumberFormatException: For input string: "    a6"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:470)
at swank.core.protocol$read_swank_message.invoke(protocol.clj:41)
at swank.core.connection$read_from_connection.invoke(connection.clj:59)
at swank.core$read_loop.invoke(core.clj:337)
at swank.swank$connection_serve$fn__1486$fn__1487.invoke(swank.clj:32)
at clojure.lang.AFn.applyToHelper(AFn.java:159)
at clojure.lang.AFn.applyTo(AFn.java:151)
at clojure.core$apply.invoke(core.clj:540)
at swank.swank$connection_serve$fn__1486.doInvoke(swank.clj:29)
at clojure.lang.RestFn.invoke(RestFn.java:397)
at clojure.lang.AFn.run(AFn.java:24)
at java.lang.Thread.run(Thread.java:636)

Update: Solved, I needed to uninstall emacs and delete ALL of /.emacs.d/, not just the packages in /elpa/. 更新:解决了,我需要卸载emacs并删除所有/.emacs.d/,而不仅仅是/ elpa /中的包。 After reinstalling I only got clojure-mode package, not slime or slime-repl. 重新安装后,我只有clojure模式包,而不是史莱姆或slime-repl。 Can now connect with Mx clojure-jack-in and am ready to do some work! 现在可以连接Mx clojure-jack-in并准备好做一些工作!

I wrote a beginner's guide for setting up Emacs + nREPL client with auto-complete and documentation popup since most old instructions weren't appropriate. 我写了一个初学者指南,用于设置Emacs + nREPL客户端,其中包含自动完成和文档弹出,因为大多数旧指令都不合适。 Available here . 在这里 May be helpful for newcomers. 可能对新手有所帮助。

you don't need to install slime and slime-repl: they are embedded into lein's plugin (see inside the jar: swank-clojure-1.4.0-SNAPSHOT.jar\\swank\\payload). 你不需要安装slime和slime-repl:它们嵌入到lein的插件中(参见jar:swank-clojure-1.4.0-SNAPSHOT.jar \\ swank \\ payload)。 You have to install just the clojure-mode. 你必须只安装clojure模式。

Also, when "reinstalling", remember to delete also the hidden folder .emacs.d in your $HOME directory, otherwise it will keep your previously downloaded Emacs plugins. 此外,在“重新安装”时,请记住在$ HOME目录中删除隐藏文件夹.emacs.d,否则它将保留以前下载的Emacs插件。

Finally prefer clojure-jack-in, not slime-connect - just having slime-connect means that you are still having a SLIME inside Emacs, so you didn't remove it. 最后更喜欢clojure-jack-in,而不是slime-connect - 只是有slime-connect意味着你仍然在Emacs中有一个SLIME,所以你没有删除它。

No need to install lein swank plugin. 无需安装lein swank插件。 You can add the dependencies in the project.clj file and just lein swank & Mx slime-connect . 您可以在project.clj文件中添加依赖项,只需添加lein swankMx slime-connect

Try with swank-clojure "1.2.1", it works for me. 试试swank-clojure“1.2.1”,它对我有用。

Try to do the following, which works for me with Emacs 24 on Ubuntu: 尝试执行以下操作,这适用于Ubuntu上的Emacs 24:

  1. Install Leiningen. 安装Leiningen。 Make sure the directory where you install lein is on the $PATH ! 确保你安装lein的目录在$PATH
  2. Install swank-clojure plugin: 安装swank-clojure插件:

    lein plugin install swank-clojure 1.3.3

  3. Create a new project with lein new . 使用lein new创建一个新项目。 Do not add swank-clojure to the :dev-dependencies . 不要将swank-clojure添加到:dev-dependencies (You really only need one or the other, the plugin or the entry in :dev-dependencies .) (你真的只需要一个或另一个,插件或条目:dev-dependencies 。)

  4. Start Emacs, making sure it can "see" lein on the $PATH , eg like this: 启动Emacs,确保它可以“看到” $PATH上的lein ,例如:

    PATH=$PATH:/path-to/dir-where/lein-is emacs

    (Use this command to try it out. For permanent use you should update the $PATH in your .profile file or install lein in a location that's already on the $PATH . In a standard Ubuntu install, ~/bin should be on the $PATH .) (使用此命令进行试用。为了永久使用,您应该更新.profile文件中的$PATH或在已经位于$PATH上的位置安装lein 。在标准的Ubuntu安装中, ~/bin应该在$PATH 。)

  5. Open a file from the project, eg project.clj , and run Mx clojure-jack-in . 从项目中打开一个文件,例如project.clj ,然后运行Mx clojure-jack-in This should start the Swank server and connect the SLIME REPL to it. 这应该启动Swank服务器并将SLIME REPL连接到它。

this happened to me when i cloned someone else's clojure project from an older version. 当我从旧版本克隆其他人的clojure项目时,这发生在我身上。 their project.clj had: 他们的project.clj有:

:dev-dependencies [[lein-clojars "0.5.0"]
                   [swank-clojure "1.2.1"]]

which is incorrect, i think, if you're using Mx clojure-jack-in . 这是不正确的,我想,如果你使用Mx clojure-jack-in removing these lines, running lein deps and jacking in worked for me. 删除这些线路,运行lein depslein deps in为我工作。

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

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