Clojure emacs slime + swank 目录问题

发布于 2024-08-16 06:29:48 字数 195 浏览 6 评论 0原文

我正在将 emacs 与 clojure-swank 和 slime 一起使用,并尝试设置我的开发环境。我遇到了一个问题。当我启动 repl 时,我被困在一个未知的目录中,阻止我加载我的命名空间。因为 clojure repl 找不到正确的文件。

有谁知道如何更改当前目录?

PS:我刚刚开始使用 emacs 和 slime,所以我是个菜鸟。

I'm using emacs with clojure-swank and slime and trying to set my development environment. And I ran into a problem. When I start a repl I'm stuck in an unknown directory preventing me to load my namespace. Because the clojure repl can't find the right file.

Does anyone know how to change the current directory?

PS: I've just started using emacs and slime so I'm a noob.

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

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

发布评论

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

评论(4

你怎么这么可爱啊 2024-08-23 06:29:48

如果您想更改 slime 对当前目录的概念,请按 ,cd ( = Enter) 并输入路径。

然而,这并不是真正解决问题的正确方法。正确的解决方案包括设置类路径,以便您可以(使用“your.namespace”)。为此,我想知道是否 这个很长的答案我提供了一个关于正确设置类路径的问题可能会有所帮助...:-)

顺便说一句,我有点反对涉及add-classpath的解决方案,因为目前已被标记为已弃用,并且从一开始就不应该被依赖...尽管另一方面,它肯定可能工作得很好,并且值得了解,以防万一它出现作为一种快速而肮脏的类路径注入技巧很方便。

现在,如果您想要一个真正漂亮的基于 SLIME 的开发环境,我想向您介绍 Phil Hagelberg 提供的一个非常好的 clojure-project elisp 函数,它设置所有相关变量并在项目的主目录(以交互方式提供)。它已发布到 Clojure 小组,事实上这里有一个链接 到该邮件的邮件档案副本。请注意,其中有一件事需要更正 - swank-clojure-jar-path 应该设置为 clojure.jar 的完整路径。否则它是一个很棒的工具。

实际上,我在此回复中提到了该函数使用 Clojure 和 Emacs 时管理类路径。其他答案可能也很有趣。

如果您刚刚开始使用 SLIME,请观看 SLIME 视频,链接到 SLIME 的主页 现在可以通过 Michiel 在评论中发布的链接访问。这是一个非常好的介绍。 :-)

If you want to change slime's notion of the current directory, press ,cd<CR> (<CR> = Enter) and type in the path.

However, this is not really the proper solution to the problem. The proper solution involves setting up the classpath so that you can (use 'your.namespace). To this end, I wonder if this very long answer I provided to a question about setting up the classpath properly might be helpful... :-)

Incidentally, I somewhat object to solutions involving add-classpath, as that is currently marked as deprecated and was never meant to be relied upon in the first place... Though on the other hand, it certainly may work perfectly well and it's worth knowing about just in case it might come in handy as a quick-and-dirty classpath injection gimmick.

Now if you want a real nice SLIME-based development environment, I'd like to point you to a very nice clojure-project elisp function by Phil Hagelberg which sets up all relevant variables and launches SLIME in the main directory of a project (to be supplied interactively). It's been posted to the Clojure group, in fact here's a link to the Mail Archive's copy of that message. Note there's one thing which needs correction in there -- swank-clojure-jar-path ought to be set to the full path to clojure.jar. Otherwise it's a fantastic tool.

Actually I mentioned that function in this response to a question about managing the classpath when using Clojure and Emacs. The other answers might be interesting as well.

And if you're only just beginning to use SLIME, do watch the SLIME video, linked to from SLIME's homepage which is now available under a link posted by Michiel in the comments. It's a very good introduction. :-)

清浅ˋ旧时光 2024-08-23 06:29:48

Leiningen 是一个新的 Clojure 构建工具,可以为您担心类路径。您在项目的根目录中设置一个简单的项目文件来指定项目的主类,它会自动发现您的 lib 目录中的所有 JAR 并为您加载它们。

现在,我只需在命令行中输入“lein swank”,然后在 Emacs 中输入 Mx slime-connect,一切就正常了。 (这可以通过一点 Elisp 轻松实现自动化。)

更多信息请参见这篇博文< /a>.

Leiningen is a new Clojure build tool that worries about classpathing for you. You set up a simple project file in the project's root directory to specify the main class of your project, and it automagically discovers all the JARs in your lib directory and loads them for you.

I now just type "lein swank" at a command line and then M-x slime-connect in Emacs, and everything just works. (This could easily be automated with a little Elisp.)

More info in this blog post.

路还长,别太狂 2024-08-23 06:29:48

简短回答:
(load-file "full-path-to-definition")

长答案:
我的引导过程如下所示:

在 ~/.clojure/user.clj 中(当您启动 slime/clojure 时,该文件会自动运行):
(add-classpath "file://path/to/foo.jar") ;将这些 jar 包含在类路径中
(add-classpath "file://path/to/foo2.jar")
(load-file "file://workspace/bootstrap.clj")

在 bootstrap.clj 中:
(compile 'my.package)

包文件位于 /workspace/my/package.clj

在 package.clj 中:
(ns my.package)
(defn foo [] (+ 2 2))

Short answer:
(load-file "full-path-to-definition")

Long answer:
Here's what my bootstrapping process looks like:

In ~/.clojure/user.clj (this file is auto-run when you boot slime/clojure):
(add-classpath "file://path/to/foo.jar") ; Include these jars in the classpath
(add-classpath "file://path/to/foo2.jar")
(load-file "file://workspace/bootstrap.clj")

In bootstrap.clj:
(compile 'my.package)

Package file(s) is at /workspace/my/package.clj

In package.clj:
(ns my.package)
(defn foo [] (+ 2 2))

岁月如刀 2024-08-23 06:29:48

我在使用 Emacs、SLIME 和 swank-clojure 时发现的最佳方法是使用 (Emacs Lisp) 函数 swank-clojure-project。从其文档中可以看出:

(swank-clojure-project PATH)

为 clojure 项目设置类路径并启动新的 SLIME 会话。
终止现有的 SLIME 会话(如果有)。

如果您执行“Mx swank-clojure-project”,它将以交互方式提示您输入项目目录;选择它后,lib 子目录中的所有 jar 以及 src 和 classes 文件夹都将添加到您的类路径中。它还将遵循 Maven/lein 目录结构,换句话说:它通常会正常工作。

如果您更改某些内容,例如添加新的 jar 文件,只需再次执行 swank-clojure-project 即可。

The best approach I've found when using Emacs, SLIME and swank-clojure is to use the (Emacs Lisp) function swank-clojure-project. From its documentation:

(swank-clojure-project PATH)

Setup classpath for a clojure project and starts a new SLIME session.
Kills existing SLIME session, if any.

If you do a "M-x swank-clojure-project", it will interactively prompt you for your project directory; once you've selected it, all the jars in a lib subdirectory, as well as the src and classes folder will be added to your classpath. It will also honor a Maven/lein directory structure, in other words: it will usually just work.

If you change something, e.g. add a new jar file, simply do swank-clojure-project again.

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