Skip to content

Commit

Permalink
added standalone swank; use prefix arg for elein-swank
Browse files Browse the repository at this point in the history
  • Loading branch information
Remco van 't Veer committed Jan 4, 2011
1 parent 3003a7d commit 1c91d02
Showing 1 changed file with 44 additions and 16 deletions.
60 changes: 44 additions & 16 deletions elein.el
Expand Up @@ -38,6 +38,11 @@
:type 'string
:group 'elein)

(defcustom elein-standalone-swank-command "~/.lein/bin/swank-clojure"
"Leiningen 'swank-clojure' command for standalone execution."
:type 'string
:group 'elein)

(defcustom elein-swank-buffer-name "*elein-swank*"
"Buffer name for swank process."
:type 'string
Expand Down Expand Up @@ -107,24 +112,47 @@
elein-swank-host
elein-swank-options))

(defun elein-standalone-swank-command ()
"Build projectless lein swank command."
(unless (file-exists-p (expand-file-name elein-standalone-swank-command))
(error "can not find %s; use 'lein install swank-clojure VERSION' to install it"
elein-standalone-swank-command))
(format "%s %d :host %s %s"
(expand-file-name elein-standalone-swank-command)
elein-swank-port
elein-swank-host
elein-swank-options))

(defun elein-burried-shell-command (command buffer)
"Same as `shell-command' but run process asynchronously, do not
show output and burry the given BUFFER."
(flet ((display-buffer (buffer-or-name &optional not-this-window frame) nil))
(bury-buffer buffer)
(shell-command (concat command "&") buffer)))

(defun elein-swank-process-filter (process output)
"Swank process filter to launch `slime-connect' when process is ready."
(with-current-buffer elein-swank-buffer-name (insert output))

(when (string-match "Connection opened on local port +\\([0-9]+\\)" output)
(slime-set-inferior-process
(slime-connect "localhost" (match-string 1 output))
process)
(set-process-filter process nil)))

;;;###autoload
(defun elein-swank ()
"Launch lein swank and connect slime to it."
(interactive)
(defun elein-swank (&optional prefix)
"Launch lein swank and connect slime to it. Interactively, a
PREFIX means launch a standalone swank session without a
project."
(interactive "P")
(let ((buffer (get-buffer-create elein-swank-buffer-name)))
(flet ((display-buffer (buffer-or-name &optional not-this-window frame) nil))
(bury-buffer buffer)
(elein-in-project-root (shell-command (concat (elein-swank-command) "&") buffer)))

(set-process-filter (get-buffer-process buffer)
(lambda (process output)
(with-current-buffer elein-swank-buffer-name (insert output))

(when (string-match "Connection opened on local port +\\([0-9]+\\)" output)
(slime-set-inferior-process
(slime-connect "localhost" (match-string 1 output))
process)
(set-process-filter process nil))))
(if prefix
(elein-burried-shell-command (elein-standalone-swank-command) buffer)
(elein-in-project-root
(elein-burried-shell-command (elein-swank-command) buffer)))

(set-process-filter (get-buffer-process buffer) #'elein-swank-process-filter)

(message "Starting swank..")))

Expand Down

0 comments on commit 1c91d02

Please sign in to comment.