emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/inf-clojure 91145b0 293/313: Function to select repls as t


From: ELPA Syncer
Subject: [nongnu] elpa/inf-clojure 91145b0 293/313: Function to select repls as the current active connection
Date: Wed, 11 Aug 2021 10:00:36 -0400 (EDT)

branch: elpa/inf-clojure
commit 91145b034ba083afe76471ea5598a912862ae7a1
Author: dan sutton <dan@dpsutton.com>
Commit: Bozhidar Batsov <bozhidar.batsov@gmail.com>

    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
---
 CHANGELOG.md   |  4 ++++
 README.md      | 11 +++++++++++
 inf-clojure.el | 23 +++++++++++++++++++++++
 3 files changed, 38 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6aaafd4..56dc45a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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.
diff --git a/README.md b/README.md
index d9c38aa..6bf9fca 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/inf-clojure.el b/inf-clojure.el
index 3832799..25457b5 100644
--- a/inf-clojure.el
+++ b/inf-clojure.el
@@ -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)
+                                        (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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]