Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### New features

* [#190](https://github.com/clojure-emacs/inf-clojure/pull/190): Helper function `inf-clojure-set-repl` to select inf-clojure process buffer.

### Bugs fixed

* [#152](https://github.com/clojure-emacs/inf-clojure/issues/152): Sanitize should only remove whitespace at the end of a command.
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,17 @@ one process, this does the right thing. If you run multiple
processes, you might need to change `inf-clojure-buffer` to
whichever process buffer you want to use.

You can use the helpful function `inf-clojure-set-repl`. If called in
an inf-clojure repl buffer, it will assign that buffer as the current
connection (`(setq inf-clojure-buffer (current-buffer)`). If you are
not in an inf-clojure repl buffer, it will offer a choice of
acceptable buffers to set as the repl buffer. If called with a prefix,
it will always give the list even if you are currently in an
acceptable repl buffer. Renaming buffers will greatly improve the
functionality of this list; the list "project-1: clojure repl",
"project-2: cljs repl" is far more understandable than "inf-clojure",
"inf-clojure<2>".

#### REPL Type

An `inf-clojure` REPL has an associated type. The available types can be
Expand Down
23 changes: 23 additions & 0 deletions inf-clojure.el
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,29 @@ has been found. See also variable `inf-clojure-buffer'."
(unless no-error
(error "No Clojure subprocess; see variable `inf-clojure-buffer'"))))

(defun inf-clojure-set-repl (always-ask)
"Set an inf clojure buffer as the active repl.
If in a repl already, use that unless a prefix is used (or
ALWAYS-ASK). Otherwise get a list of all active inf-clojure
repls and offer a choice. Recommended to rename buffers as they
are created with `rename-buffer`."
(interactive "P")
(cl-flet ((inf-clojure-repl-p () (and (derived-mode-p 'inf-clojure-mode)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest having this and a inf-clojure-repls fucntion to be top-level functions. I can imagine they'd be useful in some other situations as well.

(get-buffer-process (current-buffer))
(process-live-p (get-buffer-process (current-buffer))))))
(if (and (not always-ask)
(inf-clojure-repl-p))
(setq inf-clojure-buffer (current-buffer))
(let (repl-buffers)
(dolist (b (buffer-list))
(with-current-buffer b
(when (inf-clojure-repl-p)
(push (buffer-name b) repl-buffers))))
(if (> (length repl-buffers) 0)
(when-let ((repl-buffer (completing-read "Use for repl: " repl-buffers nil t)))
(setq inf-clojure-buffer (get-buffer repl-buffer)))
(user-error "No buffers have an inf-clojure process"))))))

(defvar-local inf-clojure-repl-type nil
"Symbol to define your REPL type.
Its root binding is nil and it can be further customized using
Expand Down