Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 22ffacd

Browse filesBrowse files
committed
Function to select repls as the current active connection
very simple: if in a repl, use that. if not in a repl, display a list of inf-clojure process buffers. If given a prefix, always show a list. Makes running simultaneous repls far easier
1 parent 3e712d9 commit 22ffacd
Copy full SHA for 22ffacd

File tree

3 files changed

+38
-0
lines changed
Filter options

3 files changed

+38
-0
lines changed

‎CHANGELOG.md

Copy file name to clipboardExpand all lines: CHANGELOG.md
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## master (unreleased)
44

5+
### New features
6+
7+
* [#190](https://github.com/clojure-emacs/inf-clojure/pull/190): Helper function `inf-clojure-set-repl` to select inf-clojure process buffer.
8+
59
### Bugs fixed
610

711
* [#152](https://github.com/clojure-emacs/inf-clojure/issues/152): Sanitize should only remove whitespace at the end of a command.

‎README.md

Copy file name to clipboardExpand all lines: README.md
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,17 @@ one process, this does the right thing. If you run multiple
316316
processes, you might need to change `inf-clojure-buffer` to
317317
whichever process buffer you want to use.
318318

319+
You can use the helpful function `inf-clojure-set-repl`. If called in
320+
an inf-clojure repl buffer, it will assign that buffer as the current
321+
connection (`(setq inf-clojure-buffer (current-buffer)`). If you are
322+
not in an inf-clojure repl buffer, it will offer a choice of
323+
acceptable buffers to set as the repl buffer. If called with a prefix,
324+
it will always give the list even if you are currently in an
325+
acceptable repl buffer. Renaming buffers will greatly improve the
326+
functionality of this list; the list "project-1: clojure repl",
327+
"project-2: cljs repl" is far more understandable than "inf-clojure",
328+
"inf-clojure<2>".
329+
319330
#### REPL Type
320331

321332
An `inf-clojure` REPL has an associated type. The available types can be

‎inf-clojure.el

Copy file name to clipboardExpand all lines: inf-clojure.el
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,29 @@ 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-set-repl (always-ask)
203+
"Set an inf clojure buffer as the active repl.
204+
If in a repl already, use that unless a prefix is used (or
205+
ALWAYS-ASK). Otherwise get a list of all active inf-clojure
206+
repls and offer a choice. Recommended to rename buffers as they
207+
are created with `rename-buffer`."
208+
(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"))))))
224+
202225
(defvar-local inf-clojure-repl-type nil
203226
"Symbol to define your REPL type.
204227
Its root binding is nil and it can be further customized using

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.