[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/inf-ruby 27fac14911 1/6: fix for duplicate prompt and long
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/inf-ruby 27fac14911 1/6: fix for duplicate prompt and long lines |
Date: |
Thu, 28 Sep 2023 13:01:33 -0400 (EDT) |
branch: elpa/inf-ruby
commit 27fac14911c63a3b21b742f8faef4936ff62d703
Author: bo-tato <122528427+bo-tato@users.noreply.github.com>
Commit: bo-tato <122528427+bo-tato@users.noreply.github.com>
fix for duplicate prompt and long lines
---
inf-ruby.el | 59 ++++++++++++++++++++++++++++++++++++++++++++---------------
1 file changed, 44 insertions(+), 15 deletions(-)
diff --git a/inf-ruby.el b/inf-ruby.el
index 88c7c9f9e6..5ea07975c3 100755
--- a/inf-ruby.el
+++ b/inf-ruby.el
@@ -495,16 +495,14 @@ process running over TRAMP, by removing the remote part
of it."
(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)
+ (let ((file (or buffer-file-name (buffer-name)))
+ line)
(save-excursion
(save-restriction
(widen)
(goto-char start)
(setq line (+ start (forward-line (- start)) 1))
- (goto-char start)
- (while (progn
- (setq term (apply 'format ruby-send-terminator (random)
(current-time)))
- (re-search-forward (concat "^" (regexp-quote term) "$") end
t)))))
+ (goto-char start)))
;; compilation-parse-errors parses from second line.
(save-excursion
(let ((m (process-mark (inf-ruby-proc))))
@@ -514,16 +512,10 @@ process running over TRAMP, by removing the remote part
of it."
(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
- (inf-ruby-file-local-name 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"))
+ (ruby-send-string (concat prefix
+ (buffer-substring-no-properties start end)
+ suffix)
+ file line)
(ruby-print-result print)))
(defface inf-ruby-result-overlay-face
@@ -683,6 +675,43 @@ This function also removes itself from `pre-command-hook'."
(point)))))
(buffer-substring-no-properties (point) (line-end-position))))))
+(defun ruby-shell--encode-string (string)
+ "Escape all backslashes, single quotes, and newlines in STRING."
+ (cl-reduce (lambda (string subst)
+ (replace-regexp-in-string (car subst) (cdr subst) string))
+ '(("\\\\" . "\\\\\\\\")
+ ("'" . "\\\\'")
+ ("\n" . "'\"\\\\n\"'"))
+ :initial-value string))
+
+(defun ruby-send-string (string &optional file line)
+ "Send STRING to the inferior Ruby process."
+ (interactive
+ (list (read-string "Ruby command: ") nil t))
+ (let* ((file-and-lineno (concat (when file
+ (format ", %S" (inf-ruby-file-local-name
file)))
+ (when (and file line)
+ (format ", %d" line))))
+ (code (format "eval('%s', %s%s)\n"
+ (ruby-shell--encode-string string)
+ inf-ruby-eval-binding
+ file-and-lineno)))
+ (if (or (null (process-tty-name (inf-ruby-proc)))
+ (<= (string-bytes code)
+ (or (bound-and-true-p comint-max-line-length)
+ 1024))) ;; For Emacs < 28
+ (comint-send-string (inf-ruby-proc) code)
+ (let ((tempfile (make-temp-file "rb")))
+ (with-temp-file tempfile
+ (insert (format "File.delete(%S)\n" tempfile))
+ (insert string)
+ (comint-send-string (inf-ruby-proc)
+ (format "eval(File.read(%S), %s%s)\n"
+ tempfile
+ inf-ruby-eval-binding
+ file-and-lineno
+ tempfile)))))))
+
(defun ruby-send-definition ()
"Send the current definition to the inferior Ruby process."
(interactive)
- [nongnu] elpa/inf-ruby updated (4714f02bd8 -> 74c8be8e27), ELPA Syncer, 2023/09/28
- [nongnu] elpa/inf-ruby a4b4e390af 2/6: fix for tramp mode, ELPA Syncer, 2023/09/28
- [nongnu] elpa/inf-ruby 6a2d3c9c28 3/6: properly clean up temp file over tramp, ELPA Syncer, 2023/09/28
- [nongnu] elpa/inf-ruby 66809aba93 4/6: simplify getting tempdir, doc and fix format arg, ELPA Syncer, 2023/09/28
- [nongnu] elpa/inf-ruby 74c8be8e27 6/6: Merge pull request #175 from bo-tato/prompt-and-long-line-fix, ELPA Syncer, 2023/09/28
- [nongnu] elpa/inf-ruby 27fac14911 1/6: fix for duplicate prompt and long lines,
ELPA Syncer <=
- [nongnu] elpa/inf-ruby f8d7404ea9 5/6: use double quoted strings to be able to use \n, ELPA Syncer, 2023/09/28