Function: cider--choose-reusable-repl-buffer
cider--choose-reusable-repl-buffer is a byte-compiled function defined
in cider-connection.el.
Signature
(cider--choose-reusable-repl-buffer PARAMS)
Documentation
Find connection-less REPL buffer and ask the user for confirmation.
Return nil if no such buffers exists or the user has chosen not to reuse
the buffer. If multiple dead REPLs exist, ask the user to choose one.
PARAMS is a plist as received by cider-repl-create.
Source Code
;; Defined in ~/.emacs.d/elpa/cider-20260414.1619/cider-connection.el
(defun cider--choose-reusable-repl-buffer (params)
"Find connection-less REPL buffer and ask the user for confirmation.
Return nil if no such buffers exists or the user has chosen not to reuse
the buffer. If multiple dead REPLs exist, ask the user to choose one.
PARAMS is a plist as received by `cider-repl-create'."
(when-let* ((repls (seq-filter (lambda (b)
(with-current-buffer b
(and (derived-mode-p 'cider-repl-mode)
(not (process-live-p (get-buffer-process b))))))
(buffer-list))))
(let* ((proj-dir (plist-get params :project-dir))
(host (plist-get params :host))
(port (plist-get params :port))
(type (plist-get params :repl-type))
(scored-repls
(mapcar (lambda (b)
(let ((bparams (ignore-errors (cider--gather-connect-params nil b))))
(when (eq type (plist-get bparams :repl-type))
(cons b (+
(if (equal proj-dir (plist-get bparams :project-dir)) 8 0)
(if (equal host (plist-get bparams :host)) 4 0)
(if (equal port (plist-get bparams :port)) 2 0))))))
repls))
(sorted-repls (mapcar #'car (seq-sort-by #'cdr #'> (delq nil scored-repls)))))
(cond ((null sorted-repls) nil)
((and (= 1 (length sorted-repls))
(eq cider-reuse-dead-repls 'prompt))
(if (y-or-n-p (format "A dead REPL %s exists. Reuse buffer? " (car sorted-repls)))
(car sorted-repls)
(and (y-or-n-p "Kill dead REPL buffer?")
(kill-buffer (car sorted-repls))
nil)))
((and (< 1 (length sorted-repls))
(memq cider-reuse-dead-repls '(prompt auto)))
(if (y-or-n-p "Dead REPL buffers exist. Select one to reuse? ")
(get-buffer (completing-read "REPL buffer to reuse: " (mapcar #'buffer-name sorted-repls)
nil t nil nil (car sorted-repls)))
(and (y-or-n-p "Kill all dead REPL buffers?")
(mapc #'kill-buffer sorted-repls)
nil)))
(cider-reuse-dead-repls ;; fallthrough for 'auto / 'any / other non-nil values
(car sorted-repls))))))