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

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

[nongnu] elpa/inf-ruby bb7d4ca086 240/265: Merge pull request #141 from


From: ELPA Syncer
Subject: [nongnu] elpa/inf-ruby bb7d4ca086 240/265: Merge pull request #141 from sharmanr/send-definition
Date: Sat, 9 Jul 2022 21:59:29 -0400 (EDT)

branch: elpa/inf-ruby
commit bb7d4ca0863fbb2b5fe96992ef0d8982058903c6
Merge: b0124578db 7593d0f355
Author: Dmitry Gutov <dgutov@yandex.ru>
Commit: GitHub <noreply@github.com>

    Merge pull request #141 from sharmanr/send-definition
    
    Change ruby-send-region to send any class and module lines that enlos…
---
 inf-ruby.el | 32 +++++++++++++++++++++++++++-----
 1 file changed, 27 insertions(+), 5 deletions(-)

diff --git a/inf-ruby.el b/inf-ruby.el
index 28233e39d6..de63949014 100755
--- a/inf-ruby.el
+++ b/inf-ruby.el
@@ -450,7 +450,7 @@ Must not contain ruby meta characters.")
 
 (defconst ruby-eval-separator "")
 
-(defun ruby-send-region (start end &optional print)
+(defun ruby-send-region (start end &optional print prefix suffix line-adjust)
   "Send the current region to the inferior Ruby process."
   (interactive "r\nP")
   (let (term (file (or buffer-file-name (buffer-name))) line)
@@ -470,10 +470,16 @@ Must not contain ruby meta characters.")
         (goto-char m)
         (insert ruby-eval-separator "\n")
         (set-marker m (point))))
+    (if line-adjust
+       (setq line (+ line line-adjust)))
     (comint-send-string (inf-ruby-proc) (format "eval <<'%s', %s, %S, %d\n"
                                                 term inf-ruby-eval-binding
                                                 file line))
+    (if prefix
+       (comint-send-string (inf-ruby-proc) prefix))
     (comint-send-region (inf-ruby-proc) start end)
+    (if suffix
+       (comint-send-string (inf-ruby-proc) suffix))
     (comint-send-string (inf-ruby-proc) (concat "\n" term "\n"))
     (when print (ruby-print-result))))
 
@@ -502,10 +508,26 @@ Must not contain ruby meta characters.")
   "Send the current definition to the inferior Ruby process."
   (interactive)
   (save-excursion
-    (end-of-defun)
-    (let ((end (point)))
-      (ruby-beginning-of-defun)
-      (ruby-send-region (point) end))))
+    (let ((orig-start (point))
+         (adjust-lineno 0)
+         prefix suffix defun-start)
+      (save-excursion
+       (end-of-line)
+       (ruby-beginning-of-defun)
+       (setq defun-start (point))
+       (unless (ruby-block-contains-point orig-start)
+         (error "point is not within a definition"))
+       (while (and (ignore-errors (backward-up-list) t)
+                   (looking-at "\\s-*\\(class\\|module\\)\\s-"))
+         (let ((line (buffer-substring-no-properties 
(line-beginning-position)(1+ (line-end-position)))))
+           (if prefix
+               (setq prefix (concat line prefix)
+                     suffix (concat suffix "end\n"))
+             (setq prefix line
+                   suffix "end\n"))
+           (setq adjust-lineno (1- adjust-lineno)))))
+      (end-of-defun)
+      (ruby-send-region defun-start (point) nil prefix suffix adjust-lineno))))
 
 (defun ruby-send-last-sexp (&optional print)
   "Send the previous sexp to the inferior Ruby process."



reply via email to

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