Skip to content

Commit 5d91ffc

Browse files
yuhan0bbatsov
authored andcommitted
Prompt to kill dead repls after choosing not to reuse them
1 parent 1f0e6c3 commit 5d91ffc

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

cider-connection.el

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -861,16 +861,24 @@ PARAMS is a plist as received by `cider-repl-create'."
861861
(if (equal port (plist-get bparams :port)) 2 0))))))
862862
repls))
863863
(sorted-repls (mapcar #'car (seq-sort-by #'cdr #'> (delq nil scored-repls)))))
864-
(when sorted-repls
865-
(cond ((eq 'any cider-reuse-dead-repls)
866-
(car sorted-repls))
867-
((= 1 (length sorted-repls))
868-
(when (or (eq 'auto cider-reuse-dead-repls)
869-
(y-or-n-p (format "A dead REPL %s exists. Reuse buffer? " (car sorted-repls))))
870-
(car sorted-repls)))
871-
((y-or-n-p "Dead REPL buffers exist. Select one to reuse? ")
872-
(get-buffer (completing-read "REPL buffer to reuse: " (mapcar #'buffer-name sorted-repls)
873-
nil t nil nil (car sorted-repls)))))))))
864+
(cond ((null sorted-repls) nil)
865+
((and (= 1 (length sorted-repls))
866+
(eq cider-reuse-dead-repls 'prompt))
867+
(if (y-or-n-p (format "A dead REPL %s exists. Reuse buffer? " (car sorted-repls)))
868+
(car sorted-repls)
869+
(and (y-or-n-p "Kill dead REPL buffer?")
870+
(kill-buffer (car sorted-repls))
871+
nil)))
872+
((and (< 1 (length sorted-repls))
873+
(memq cider-reuse-dead-repls '(prompt auto)))
874+
(if (y-or-n-p "Dead REPL buffers exist. Select one to reuse? ")
875+
(get-buffer (completing-read "REPL buffer to reuse: " (mapcar #'buffer-name sorted-repls)
876+
nil t nil nil (car sorted-repls)))
877+
(and (y-or-n-p "Kill all dead REPL buffers?")
878+
(mapc #'kill-buffer sorted-repls)
879+
nil)))
880+
(cider-reuse-dead-repls ;; fallthrough for 'auto / 'any / other non-nil values
881+
(car sorted-repls))))))
874882

875883
(declare-function cider-default-err-handler "cider-eval")
876884
(declare-function cider-repl-mode "cider-repl")

0 commit comments

Comments
 (0)