[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)))))
- [nongnu] elpa/inf-ruby dfc1d4f19f 033/265: Delete obsolete TODO comment, (continued)
- [nongnu] elpa/inf-ruby dfc1d4f19f 033/265: Delete obsolete TODO comment, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 6aba85ea70 042/265: inf-ruby-fix-completions-on-windows: Fix free variable compilation warning, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 5cf94a2dd1 010/265: Fix completion string insertion so that it doesn't swallow newlines when used outside of inf-ruby buffers., ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 0f0eb184f0 088/265: Bump the version, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby f062b7eb0b 075/265: Merge remote-tracking branch 'bbatsov/readme', ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 8fa68039c8 160/265: Improving inf-ruby-breakpoint-pattern and in-ruby-compilation-modes, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 5bb2919691 155/265: Keep the buffer's restrictions, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby e18c8c3624 162/265: Considering ^D as a valid exit command, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 4d410007a2 169/265: Fix ruby-send-definition, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 9c4d799faf 183/265: inf-ruby-console-zeus: Add docstring, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 700c453610 181/265: Merge pull request #91 from asok/multi,
ELPA Syncer <=
- [nongnu] elpa/inf-ruby 54eb6bf6d6 185/265: Bump the version, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 57710da5c8 214/265: inf-ruby-console-gem: Use '--prompt default --noreadline', ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby c2bb2f7186 215/265: Add ruby-send-{buffer, line}-and-go commands, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 6bfa7c9411 217/265: Add `ansi-color-process-output` to comint output functions, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby d2cc45ac1a 221/265: Bump the version, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 4a7ed23971 222/265: Revert "Add `ansi-color-process-output` to comint output functions", ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 928b1dd2c2 223/265: Merge pull request #123 from nonsequitur/revert-118-master, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby b228a7d9af 225/265: inf-ruby-error-regexp-alist: bol-anchor for better performance, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 1b89400e6f 227/265: Add '--nomultiline' with newer IRB versions, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 41e5ed3a88 229/265: run-ruby: Update for the latest change, ELPA Syncer, 2022/07/09