首页 文章

使用elisp运行'lein swank'(调用clojure服务器)

提问于
浏览
1

正如被问及并回答here . 我可以使用'lein swank'在Aquamacs上运行clojure .

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

  • 问:有没有办法自动解决这个问题?我的意思是当调用slime / clojure(M-x slime-connect)时,如何自动运行命令'lein swank' .

  • 问:如果我必须提出运行'lein swank'的elisp代码,我该怎么做?

已添加

根据JürgenHö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字符串里面就不会让它运行了 .

1 回答

  • 1

    我为这份工作做了一个要点:

    http://gist.github.com/419364

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

    我对 lein-swank 做了几处改进:

    • lein-swank-command 现在可自定义:如果Leiningen的 bin 目录不属于您的 PATH 环境,则可以使用它 .

    • 添加了 directory 作为交互式参数:如果在当前目录的主导位置找不到 project.clj ,则可以指定位置 .

相关问题