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

发布于 2024-12-11 13:33:39 字数 3341 浏览 0 评论 0原文

简短版本:使用 lein swank 启动 swank 服务器时运行 Mx slime-connect 或 Mx clojure-jack-in 时出错。

我在 Ubuntu 10.10 上使用 emacs 24.0.50.1。我已经从 ELPA 在 emacs 中安装了以下软件包:clojure-mode、paredit、slime、slime-repl

我从 github 安装了 leiningen将其添加到类路径中,然后运行 lein 插件安装 swank-clojure 1.3.3。 之后我创建了一个新目录 ~/tmp/,cd 进入它并运行: lein new test-project 似乎设置一切正常。然后我在 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"]])

之后我返回 /tmp/new-project 文件夹并运行 lein deps 然后运行 ​​lein swank 下载依赖项并启动 swank 服务器,该服务器给出输出:

Connection opened on local port 4005.

回到 emacs 中,我遇到了连接到 swank 服务器的问题。我尝试打开 core.clj 文件并运行 Mx slime-connect ,它给出了错误:

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

这让我认为它要么没有看到 swank 服务器正在运行,要么需要一些配置完成后即可看到服务器。我还尝试了(打开相同的文件并打开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")

:遵循 http://matthias-schneider.org/docs/clojure-setup/ 获取 emacs 软件包和 lein 设置,然后开始按照 http://riddell.us/ClojureSwankLeiningenWithEmacsOnLinux.html 一旦我在使用 Mx slime-connect 打开 REPL 时遇到问题。

更新

删除 ~/tmp/test-project,卸载 emacs 和 /.emacs.d/elpa/ 软件包,重新安装 emacs,重新安装 clojure-mode 和 paredit 软件包,将 ~/.lein 复制到 /bin确保没有路径问题(不确定 /.lein 或 /.lein/bin 是否需要位于路径中)。运行 /.lein/bin/swank-clojure ,然后打开 emacs,打开 project.clj,并尝试 Mx slime-connect,它现在要求我提供主机(本地默认),端口(默认 4005),表示连接到 swank,给出一条有关 swank 和 slime 版本不同(y 或 n)y 的消息,然后迷你缓冲区在进程过滤器中给出错误: Lisp 连接意外关闭。在我运行 /.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)

更新: 解决了,我需要卸载 emacs 并删除所有 /.emacs.d/,而不仅仅是 /elpa/ 中的包。重新安装后我只得到了 clojure-mode 包,而不是 slime 或 slime-repl。现在可以与 Mx clojure-jack-in 连接并准备好做一些工作!

Short version: errors when running M-x slime-connect or M-x clojure-jack-in when using lein swank to start the swank server.

I'm using emacs 24.0.50.1 on Ubuntu 10.10. I've installed the following packages in emacs from ELPA: 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.
After that I created a new directory ~/tmp/, cd into it and ran:
lein new test-project which seemed to setup everything ok. Then I opened up /tmp/new-project/project.clj in emacs and changed it to:

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

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. I've tried opening the core.clj file and running M-x slime-connect which gives the error:

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. I also tried (with the same file open and with project.clj open) M-x clojure-jack-inwhich I assume tries to start the clojure REPL in the project folder but that gives the following:

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 M-x slime-connect to open a 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). Ran /.lein/bin/swank-clojure and then opened emacs, opened the project.clj, and tried M-x 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. In the terminal where I ran /.lein/bin/swank-clojure the following java error pops up:

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/. After reinstalling I only got clojure-mode package, not slime or slime-repl. Can now connect with M-x clojure-jack-in and am ready to do some work!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

别念他 2024-12-18 13:33:39

你不需要安装 slime 和 slime-repl:它们嵌入到 lein 的插件中(参见 jar 内部:swank-clojure-1.4.0-SNAPSHOT.jar\swank\payload)。您必须仅安装 clojure 模式。

另外,“重新安装”时,请记住删除 $HOME 目录中的隐藏文件夹 .emacs.d,否则它将保留您之前下载的 Emacs 插件。

最后,更喜欢 clojure-jack-in,而不是 slime-connect - 只要有 slime-connect 就意味着你在 Emacs 中仍然有一个 SLIME,所以你没有删除它。

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). You have to install just the clojure-mode.

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.

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.

梦中楼上月下 2024-12-18 13:33:39

我编写了一份初学者指南,用于设置带有自动完成和文档弹出窗口的 Emacs + nREPL 客户端,因为大多数旧的说明都不合适。位于此处。可能对新人有帮助。

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. Available here. May be helpful for newcomers.

甜宝宝 2024-12-18 13:33:39

无需安装 lein swank 插件。您可以在project.clj 文件中添加依赖项,然后只需lein swank & Mx slime-connect

尝试使用 swank-clojure“1.2.1”,它对我有用。

No need to install lein swank plugin. You can add the dependencies in the project.clj file and just lein swank & M-x slime-connect.

Try with swank-clojure "1.2.1", it works for me.

荒路情人 2024-12-18 13:33:39

尝试执行以下操作,这对我在 Ubuntu 上使用 Emacs 24 有效:

  1. 安装 Leiningen。确保安装lein的目录位于$PATH上!
  2. 安装 swank-clojure 插件:

    lein plugin install swank-clojure 1.3.3

  3. 创建一个使用lein new创建新项目。不要将 swank-clojure 添加到 :dev-dependencies 中。 (您实际上只需要其中之一,插件或 :dev-dependency 中的条目。)

  4. 启动 Emacs,确保它可以“看到”lein$PATH 上,例如:

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

    (使用此命令进行尝试。要永久使用,您应该更新 .profile 文件中的 $PATH 或安装 lein位于 $PATH 上的位置。在标准 Ubuntu 安装中,~/bin 应位于 $PATH 上。)

  5. 从项目中打开一个文件,例如 project.clj,并且运行 Mx clojure-jack-in 。这应该启动 Swank 服务器并将 SLIME REPL 连接到它。

Try to do the following, which works for me with Emacs 24 on Ubuntu:

  1. Install Leiningen. Make sure the directory where you install lein is on the $PATH!
  2. Install swank-clojure plugin:

    lein plugin install swank-clojure 1.3.3

  3. Create a new project with lein new. Do not add swank-clojureto the :dev-dependencies. (You really only need one or the other, the plugin or the entry in :dev-dependencies.)

  4. Start Emacs, making sure it can "see" lein on the $PATH, e.g. like this:

    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.)

  5. Open a file from the project, e.g. project.clj, and run M-x clojure-jack-in. This should start the Swank server and connect the SLIME REPL to it.

月亮是我掰弯的 2024-12-18 13:33:39

当我从旧版本克隆别人的 clojure 项目时,这发生在我身上。他们的project.clj有:

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

如果您使用Mx clojure-jack-in,我认为这是不正确的。删除这些行,运行 lein deps 并插入对我有用。

this happened to me when i cloned someone else's clojure project from an older version. their project.clj had:

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

which is incorrect, i think, if you're using M-x clojure-jack-in. removing these lines, running lein deps and jacking in worked for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文