[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/inf-ruby 0ed06255ec 179/265: Allow running multiple ruby p
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/inf-ruby 0ed06255ec 179/265: Allow running multiple ruby processes |
Date: |
Sat, 9 Jul 2022 21:59:24 -0400 (EDT) |
branch: elpa/inf-ruby
commit 0ed06255ec60f4bff28f142f86f6c9df5befd4c8
Author: Adam Sokolnicki <adam.sokolnicki@gmail.com>
Commit: Adam Sokolnicki <adam.sokolnicki@gmail.com>
Allow running multiple ruby processes
---
inf-ruby.el | 69 +++++++++++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 53 insertions(+), 16 deletions(-)
diff --git a/inf-ruby.el b/inf-ruby.el
index 340c96d6d2..d12e93df34 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 23929579a6 124/265: Merge pull request #57 from bbatsov/compilation-warnings, (continued)
- [nongnu] elpa/inf-ruby 23929579a6 124/265: Merge pull request #57 from bbatsov/compilation-warnings, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby e4cf0593da 116/265: inf-ruby-console-gem: require the main file if it exists, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 27acc75257 113/265: inf-ruby-console-rails: prompt for the environment, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 0697315485 109/265: Merge pull request #52 from abicky/support-dir-without-traiing-slash, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 451aa1d858 145/265: Merge pull request #71 from jasonko/master, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 46917f463c 151/265: Integrate with projectile-rails-server-mode, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 4962bb076e 141/265: inf-ruby-console-patterns-alist: Accept predicate function in cars, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby c59d7d0a23 134/265: inf-ruby-console-default: Prioritize console.rb if it exists, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby e91b349e4f 168/265: Hook up inf-ruby-auto-exit inside inf-ruby-auto-enter, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 106972ded1 165/265: Touch up docstrings and rename MODE-VAR to MODE, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 0ed06255ec 179/265: Allow running multiple ruby processes,
ELPA Syncer <=
- [nongnu] elpa/inf-ruby 536a68528c 184/265: Make ruby-last-ruby-buffer buffer-local, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby d1e6e9e669 003/265: Bugfix: Escape the completion seed., ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby ed768ce413 004/265: Evaluate code sent via 'ruby-send-region' in the same binding as the REPL., ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 68a7ad32fa 006/265: Bugfix: Don't stall Emacs when there is no valid completion output., ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 06e2b1e29e 008/265: Bugfix: Complete only when point is at a top-level prompt., ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby ec0d30ad19 019/265: Merge pull request #5 from lewang/quote_fix, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby f52d33ec43 016/265: Transform an unneded case statement into an if statement., ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 28c24e3e70 021/265: Merge pull request #7 from lewang/patch-1, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby f2e7cc8313 025/265: Restrict a Windows-specific fix to be applied only on Windows platforms., ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 415eb2dfd8 018/265: allow quoted parameters to run-ruby, ELPA Syncer, 2022/07/09