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.