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

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

[nongnu] elpa/inf-ruby 12f7f0750c 159/265: Automatically returning to th


From: ELPA Syncer
Subject: [nongnu] elpa/inf-ruby 12f7f0750c 159/265: Automatically returning to the previous compilation mode after typing
Date: Sat, 9 Jul 2022 21:59:22 -0400 (EDT)

branch: elpa/inf-ruby
commit 12f7f0750c1ee65da35c2cfa3b6eb180a59e1913
Author: Daniel Luna <dancluna@gmail.com>
Commit: Daniel Luna <dancluna@gmail.com>

    Automatically returning to the previous compilation mode after typing
    'quit' or 'exit' in the debugger prompt.
---
 README.md   |  2 +-
 inf-ruby.el | 32 ++++++++++++++++++++++++++++----
 2 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md
index 21a92732c9..e430e2150a 100644
--- a/README.md
+++ b/README.md
@@ -60,7 +60,7 @@ automatically.
 Additionally, consider adding
 
 ```lisp
-(add-hook 'compilation-filter-hook 'inf-ruby-auto-enter)
+(inf-ruby-setup-auto-breakpoint)
 ```
 
 to your init file to automatically switch from common Ruby compilation
diff --git a/inf-ruby.el b/inf-ruby.el
index 1ade40fa7b..1cff6b211c 100755
--- a/inf-ruby.el
+++ b/inf-ruby.el
@@ -735,12 +735,36 @@ Gemfile, it should use the `gemspec' instruction."
   (let ((default-directory (file-name-as-directory dir)))
     (run-ruby "bundle exec racksh" "racksh")))
 
+(defmacro in-ruby-compilation-modes (mode-var &rest body)
+  "Checks if we're in a ruby compilation mode, and runs BODY in an
+implicit progn if t."
+  `(when (member ,mode-var '(rspec-compilation-mode
+                              ruby-compilation-mode
+                              projectile-rails-server-mode))
+     (progn ,@body)))
+
 (defun inf-ruby-auto-enter ()
   "Automatically enters inf-ruby mode when it sees a breakpoint-indicating 
pattern."
-  (when (member major-mode '(rspec-compilation-mode ruby-compilation-mode 
projectile-rails-server-mode))
-    (beginning-of-line)
-    (when (re-search-forward inf-ruby-breakpoint-pattern (line-end-position) t)
-      (inf-ruby-switch-from-compilation))))
+  (in-ruby-compilation-modes major-mode
+                             (save-excursion
+                               (beginning-of-line)
+                               (when (looking-at inf-ruby-breakpoint-pattern)
+                                 (inf-ruby-switch-from-compilation)))))
+
+(defun inf-ruby-auto-exit (input)
+  "Checks if the current input is a debugger exit command and returns
+to the previous compilation mode if t."
+  (in-ruby-compilation-modes inf-ruby-orig-compilation-mode
+                             (if (member input '("quit" "exit"))
+                                 (inf-ruby-maybe-switch-to-compilation))))
+
+(defun inf-ruby-setup-auto-breakpoint ()
+  (add-hook 'compilation-filter-hook 'inf-ruby-auto-enter)
+  (add-hook 'comint-input-filter-functions 'inf-ruby-auto-exit))
+
+(defun inf-ruby-remove-auto-breakpoint ()
+  (remove-hook 'compilation-filter-hook 'inf-ruby-auto-enter)
+  (remove-hook 'comint-input-filter-functions 'inf-ruby-auto-exit))
 
 ;;;###autoload
 (defun inf-ruby-console-default (dir)



reply via email to

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