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

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

[nongnu] elpa/inf-ruby 700c453610 181/265: Merge pull request #91 from a


From: ELPA Syncer
Subject: [nongnu] elpa/inf-ruby 700c453610 181/265: Merge pull request #91 from asok/multi
Date: Sat, 9 Jul 2022 21:59:24 -0400 (EDT)

branch: elpa/inf-ruby
commit 700c453610fa9737d8fb27f9c0aa8aecc029c1d6
Merge: 8b198d01e9 0ed06255ec
Author: Dmitry Gutov <dgutov@yandex.ru>
Commit: GitHub <noreply@github.com>

    Merge pull request #91 from asok/multi
    
    Allow running multiple inf-ruby process
---
 inf-ruby.el | 69 +++++++++++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 53 insertions(+), 16 deletions(-)

diff --git a/inf-ruby.el b/inf-ruby.el
index 39399290ec..e2723e63aa 100755
--- a/inf-ruby.el
+++ b/inf-ruby.el
@@ -191,7 +191,15 @@ The following commands are available:
 \\{inf-ruby-minor-mode-map}"
   :lighter "" :keymap inf-ruby-minor-mode-map)
 
-(defvar inf-ruby-buffer nil "Current Ruby process buffer.")
+(defvar inf-ruby-buffer nil "Last used Ruby process buffer.")
+
+(defvar inf-ruby-buffers nil "List of Ruby process buffers.")
+
+(defvar inf-ruby-buffer-command nil "The command used to run Ruby shell")
+(make-variable-buffer-local 'inf-ruby-buffer-command)
+
+(defvar inf-ruby-buffer-impl-name nil "The name of the Ruby shell")
+(make-variable-buffer-local 'inf-ruby-buffer-impl-name)
 
 (defun inf-ruby-mode ()
   "Major mode for interacting with an inferior Ruby REPL process.
@@ -282,6 +290,18 @@ The following commands are available:
       (inf-ruby-remove-in-string (buffer-substring (point) end)
                                  inf-ruby-prompt-pattern))))
 
+(defun inf-ruby-buffer ()
+  "Return inf-ruby buffer for the current buffer or project."
+  (catch 'buffer
+    (let ((current-dir (expand-file-name
+                        (locate-dominating-file default-directory
+                                                #'inf-ruby-console-match))))
+      (dolist (buffer inf-ruby-buffers)
+        (when (buffer-live-p buffer)
+          (with-current-buffer buffer
+            (when (string= (expand-file-name default-directory) current-dir)
+              (throw 'buffer buffer))))))))
+
 ;;;###autoload
 (defun inf-ruby (&optional impl)
   "Run an inferior Ruby process in a buffer.
@@ -301,8 +321,11 @@ run)."
 
 ;;;###autoload
 (defun run-ruby (&optional command name)
-  "Run an inferior Ruby process, input and output via buffer `*NAME*'.
-If there is a process already running in `*NAME*', switch to that buffer.
+  "Run an inferior Ruby process in a buffer related to the current project.
+If there is a process already running in a corresponding buffer,
+switch to that buffer. Otherwise create a new buffer.
+The consecutive buffer names will be:
+`*NAME*', `*NAME*<2>', `*NAME*<3>' and so on.
 
 NAME defaults to \"ruby\". COMMAND defaults to the default entry
 in `inf-ruby-implementations'.
@@ -314,26 +337,39 @@ in `inf-ruby-implementations'.
                                         inf-ruby-implementations))))
   (setq name (or name "ruby"))
 
-  (if (not (comint-check-proc inf-ruby-buffer))
+  (if (not (comint-check-proc (inf-ruby-buffer)))
       (let ((commandlist (split-string-and-unquote command))
             (buffer (current-buffer))
             (process-environment process-environment))
         ;; http://debbugs.gnu.org/15775
         (setenv "PAGER" (executable-find "cat"))
-        (set-buffer (apply 'make-comint name (car commandlist)
+        (set-buffer (apply 'make-comint-in-buffer
+                           name
+                           (generate-new-buffer-name (format "*%s*" name))
+                           (car commandlist)
                            nil (cdr commandlist)))
         (inf-ruby-mode)
-        (ruby-remember-ruby-buffer buffer)))
-  (pop-to-buffer (setq inf-ruby-buffer (format "*%s*" name))))
+        (ruby-remember-ruby-buffer buffer)
+        (push (current-buffer) inf-ruby-buffers)
+        (setq inf-ruby-buffer-impl-name name
+              inf-ruby-buffer-command command)))
+
+  (let ((buffer (inf-ruby-buffer)))
+    (with-current-buffer buffer
+      (if (and (string= inf-ruby-buffer-impl-name name)
+               (string= inf-ruby-buffer-command command))
+          (pop-to-buffer (setq inf-ruby-buffer buffer))
+        (error "Found inf-ruby buffer for directory %s but it was run with 
different COMMAND and/or NAME."
+               (expand-file-name default-directory))))))
 
 (defun inf-ruby-proc ()
-  "Return the current inferior Ruby process.
+  "Return the inferior Ruby process for the current buffer or project.
 
-See variable `inf-ruby-buffer'."
+See variable `inf-ruby-buffers'."
   (or (get-buffer-process (if (eq major-mode 'inf-ruby-mode)
                               (current-buffer)
-                            inf-ruby-buffer))
-      (error "No current process. See variable inf-ruby-buffer")))
+                            (inf-ruby-buffer)))
+      (error "No current process. See variable inf-ruby-buffers")))
 
 ;; These commands are added to the ruby-mode keymap:
 
@@ -378,7 +414,7 @@ Must not contain ruby meta characters.")
   "Print the result of the last evaluation in the current buffer."
   (let ((proc (inf-ruby-proc)))
     (insert
-     (with-current-buffer inf-ruby-buffer
+     (with-current-buffer (inf-ruby-buffer)
        (while (not (and comint-last-prompt
                         (goto-char (car comint-last-prompt))
                         (looking-at inf-ruby-first-prompt-pattern)))
@@ -430,12 +466,13 @@ Must not contain ruby meta characters.")
   "Switch to the ruby process buffer.
 With argument, positions cursor at end of buffer."
   (interactive "P")
-  (let ((buffer (current-buffer)))
-    (if (and inf-ruby-buffer (get-buffer inf-ruby-buffer))
+  (let ((buffer (current-buffer))
+        (inf-ruby-buffer* (or (inf-ruby-buffer) inf-ruby-buffer)))
+    (if inf-ruby-buffer*
         (progn
-          (pop-to-buffer inf-ruby-buffer)
+          (pop-to-buffer inf-ruby-buffer*)
           (ruby-remember-ruby-buffer buffer))
-      (error "No current process buffer, see variable inf-ruby-buffer")))
+      (error "No current process buffer, see variable inf-ruby-buffers")))
   (cond (eob-p
          (push-mark)
          (goto-char (point-max)))))



reply via email to

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