Skip to content

Commit f24722c

Browse files
dpsuttonbbatsov
authored andcommitted
Extract useful functions
1 parent 91145b0 commit f24722c

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

inf-clojure.el

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -199,28 +199,37 @@ has been found. See also variable `inf-clojure-buffer'."
199199
(unless no-error
200200
(error "No Clojure subprocess; see variable `inf-clojure-buffer'"))))
201201

202+
(defun inf-clojure-repl-p ()
203+
"Indicates if current buffer is an inf-clojure repl.
204+
Checks the mode and that there is a live process."
205+
(and (derived-mode-p 'inf-clojure-mode)
206+
(get-buffer-process (current-buffer))
207+
(process-live-p (get-buffer-process (current-buffer)))))
208+
209+
(defun inf-clojure-repls-list ()
210+
"Return a list of all known inf-clojure repls."
211+
(let (repl-buffers)
212+
(dolist (b (buffer-list))
213+
(with-current-buffer b
214+
(when (inf-clojure-repl-p)
215+
(push (buffer-name b) repl-buffers))))
216+
repl-buffers))
217+
202218
(defun inf-clojure-set-repl (always-ask)
203219
"Set an inf clojure buffer as the active repl.
204220
If in a repl already, use that unless a prefix is used (or
205221
ALWAYS-ASK). Otherwise get a list of all active inf-clojure
206222
repls and offer a choice. Recommended to rename buffers as they
207223
are created with `rename-buffer`."
208224
(interactive "P")
209-
(cl-flet ((inf-clojure-repl-p () (and (derived-mode-p 'inf-clojure-mode)
210-
(get-buffer-process (current-buffer))
211-
(process-live-p (get-buffer-process (current-buffer))))))
212-
(if (and (not always-ask)
213-
(inf-clojure-repl-p))
214-
(setq inf-clojure-buffer (current-buffer))
215-
(let (repl-buffers)
216-
(dolist (b (buffer-list))
217-
(with-current-buffer b
218-
(when (inf-clojure-repl-p)
219-
(push (buffer-name b) repl-buffers))))
220-
(if (> (length repl-buffers) 0)
221-
(when-let ((repl-buffer (completing-read "Use for repl: " repl-buffers nil t)))
222-
(setq inf-clojure-buffer (get-buffer repl-buffer)))
223-
(user-error "No buffers have an inf-clojure process"))))))
225+
(if (and (not always-ask)
226+
(inf-clojure-repl-p))
227+
(setq inf-clojure-buffer (current-buffer))
228+
(let ((repl-buffers (inf-clojure-repls-list)))
229+
(if (> (length repl-buffers) 0)
230+
(when-let ((repl-buffer (completing-read "Use for repl: " repl-buffers nil t)))
231+
(setq inf-clojure-buffer (get-buffer repl-buffer)))
232+
(user-error "No buffers have an inf-clojure process")))))
224233

225234
(defvar-local inf-clojure-repl-type nil
226235
"Symbol to define your REPL type.

0 commit comments

Comments
 (0)