diff options
author | Bozhidar Batsov <bozhidar@batsov.com> | 2015-09-06 13:21:06 +0300 |
---|---|---|
committer | Bozhidar Batsov <bozhidar@batsov.com> | 2015-09-06 13:21:06 +0300 |
commit | d927a8cadfb092fd124d210ff10aab792a288167 (patch) | |
tree | 0aa1bfade09d3e41167b62146298a7a769bf80ea /cider.el | |
parent | 77bfd942927a68878789ba18a7c4fc362864b877 (diff) |
Move nrepl-find-reusable-repl-buffer to cider.el
This commit also renames it to cider-find-reusable-repl-buffer.
Diffstat (limited to 'cider.el')
-rw-r--r-- | cider.el | 39 |
1 files changed, 37 insertions, 2 deletions
@@ -215,6 +215,41 @@ should be the regular Clojure REPL started by the server process filter." "code" cider-cljs-repl) (cider-repl-handler (current-buffer)))))) +(defun cider-find-reusable-repl-buffer (endpoint project-directory) + "Check whether a reusable connection buffer already exists. +Looks for buffers where `nrepl-endpoint' matches ENDPOINT, or +`nrepl-project-dir' matches PROJECT-DIRECTORY. If such a buffer was found, +and has no process, return it. If the process is alive, ask the user for +confirmation and return 'new/nil for y/n answer respectively. If other +REPL buffers with dead process exist, ask the user if any of those should +be reused." + (let* ((repl-buffs (cider-repl-buffers)) + (exact-buff (-first (lambda (buff) + (with-current-buffer buff + (or (and endpoint (equal endpoint nrepl-endpoint)) + (and project-directory (equal project-directory nrepl-project-dir))))) + repl-buffs))) + (cl-flet ((zombie-buffer-or-new + () (let ((zombie-buffs (-remove (lambda (buff) + (process-live-p (get-buffer-process buff))) + repl-buffs))) + (if zombie-buffs + (if (y-or-n-p (format "Zombie REPL buffers exist (%s). Reuse? " + (mapconcat #'buffer-name zombie-buffs ", "))) + (if (= (length zombie-buffs) 1) + (car zombie-buffs) + (completing-read "Choose REPL buffer: " zombie-buffs nil t)) + 'new) + 'new)))) + (if exact-buff + (if (process-live-p (get-buffer-process exact-buff)) + (when (y-or-n-p + (format "REPL buffer already exists (%s). Do you really want to create a new one? " + exact-buff)) + (zombie-buffer-or-new)) + exact-buff) + (zombie-buffer-or-new))))) + ;;;###autoload (defun cider-jack-in (&optional prompt-project cljs-too) "Start a nREPL server for the current project and connect to it. @@ -236,7 +271,7 @@ own buffer." (cider-jack-in-params project-type)) (cider-jack-in-params project-type))) (cmd (format "%s %s" (cider-jack-in-command project-type) params))) - (-when-let (repl-buff (nrepl-find-reusable-repl-buffer nil project-dir)) + (-when-let (repl-buff (cider-find-reusable-repl-buffer nil project-dir)) (let ((nrepl-create-client-buffer-function #'cider-repl-create) (nrepl-use-this-as-repl-buffer repl-buff)) (nrepl-start-server-process @@ -259,7 +294,7 @@ start the server." Create REPL buffer and start an nREPL client connection." (interactive (cider-select-endpoint)) (setq cider-current-clojure-buffer (current-buffer)) - (-when-let (repl-buff (nrepl-find-reusable-repl-buffer `(,host ,port) nil)) + (-when-let (repl-buff (cider-find-reusable-repl-buffer `(,host ,port) nil)) (let* ((nrepl-create-client-buffer-function #'cider-repl-create) (nrepl-use-this-as-repl-buffer repl-buff) (conn (process-buffer (nrepl-start-client-process host port)))) |