奔跑“lein swank” (调用 clojure 服务器)使用 elisp

发布于 2024-09-12 01:19:59 字数 1824 浏览 5 评论 0原文

正如此处所询问和回答的那样。我可以使用“lein swank”在 Aquamacs 上运行 clojure。

我需要在运行 slime/clojure 之前自动运行 'lein swank'。

  • 问:有没有办法自动做到这一点?我的意思是,当调用 slime/clojure (Mx slime-connect) 时,如何自动运行命令“lein swank”。
  • 问:如果我必须想出 elisp 代码来运行“lein swank”,我该怎么做?

添加

基于 Jürgen Hötzel 的回答,我修改了 elisp,如下所示。

(defun lein-swank ()
(interactive)
(let ((default-directory (locate-dominating-file default-directory "/Users/smcho/bin/leiningen")))
  (when (not default-directory)
    (error "Not in a Leiningen project."))
  ;; you can customize slime-port using .dir-locals.el
  (let ((proc (start-process "lein-swank" nil "/Users/smcho/bin/leiningen/bin/lein" "swank" (number-to-string 4005))))
    (when proc
    (process-put proc :output nil)
    (set-process-sentinel proc (lambda (proc event)
                     (message "%s%s: `%S'" 
                          (process-get proc :output)
                          proc (replace-regexp-in-string "\n" "" event))))
    (set-process-filter proc
                (lambda (proc output)
                  ;; record last line of output until connected (possible error message)
                  (process-put proc :output (concat (process-get proc :output) output))
                  (when (string-match "Connection opened on" output)
                (slime-connect "localhost" 4005)
                ;; no need to further process output
                (set-process-filter proc nil))))
    (message "Starting swank server...")))))

但是,我收到了这个错误。

No project.clj found in this directory. lein-swank: `"exited abnormally with code 1"'.

我发现我应该将 pwd 更改为 ~/bin/leiningen 才能运行“lein swank”。仅将 lein 二进制文件放入 PATH 字符串中并不能使其运行。

As is asked and answered here. I could use 'lein swank' to run clojure on Aquamacs.

I need to automate running 'lein swank', before running slime/clojure.

  • Q : Is there a way to this automatically? I mean how can I run the command 'lein swank' automatically when slime/clojure (M-x slime-connect) is called.
  • Q : If I have to come up with elisp code to run 'lein swank', how can I do that?

Added

Based on Jürgen Hötzel's answer, I modified the elisp as follows.

(defun lein-swank ()
(interactive)
(let ((default-directory (locate-dominating-file default-directory "/Users/smcho/bin/leiningen")))
  (when (not default-directory)
    (error "Not in a Leiningen project."))
  ;; you can customize slime-port using .dir-locals.el
  (let ((proc (start-process "lein-swank" nil "/Users/smcho/bin/leiningen/bin/lein" "swank" (number-to-string 4005))))
    (when proc
    (process-put proc :output nil)
    (set-process-sentinel proc (lambda (proc event)
                     (message "%s%s: `%S'" 
                          (process-get proc :output)
                          proc (replace-regexp-in-string "\n" "" event))))
    (set-process-filter proc
                (lambda (proc output)
                  ;; record last line of output until connected (possible error message)
                  (process-put proc :output (concat (process-get proc :output) output))
                  (when (string-match "Connection opened on" output)
                (slime-connect "localhost" 4005)
                ;; no need to further process output
                (set-process-filter proc nil))))
    (message "Starting swank server...")))))

But, I got this error.

No project.clj found in this directory. lein-swank: `"exited abnormally with code 1"'.

What I found was that I should change pwd to ~/bin/leiningen to run 'lein swank'. Just put lein binary inside the PATH string doesn't make it run.

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

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

发布评论

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

评论(1

十级心震 2024-09-19 01:19:59

我为这项工作提出了要点:

http://gist.github.com/419364

只需使用交互式命令“Mx lein-swank”,它将在当前目录中生成命令并连接到它。

我对 lein-swank 进行了一些改进:

  1. lein-swank-command 现在可以自定义:您可以使用 Leiningen,如果它的 bin目录不是您的 PATH 环境的一部分。

  2. 添加了目录作为交互参数:如果在当前目录的主要位置找不到project.clj,您可以指定一个位置。

I made a gist for this job:

http://gist.github.com/419364

Just use the interactive command "M-x lein-swank", which will spawn the command in the current directory and connect to it.

I made several improvements to lein-swank:

  1. lein-swank-command is now customizable: You can use Leiningen, if its bin directory is not part of your PATH environment.

  2. Added directory as interactive argument: If project.clj can not be found in a dominating location of your current directory, you can specify a location.

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