开发者

Running 'lein swank' (calling clojure server) with elisp

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 f开发者_如何学Goound 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜