[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/inf-ruby beb39ad5af 148/265: Define and use ruby-print-res
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/inf-ruby beb39ad5af 148/265: Define and use ruby-print-result |
Date: |
Sat, 9 Jul 2022 21:59:21 -0400 (EDT) |
branch: elpa/inf-ruby
commit beb39ad5af8777769367d6458329036bb7064e89
Author: Dmitry Gutov <dgutov@yandex.ru>
Commit: Dmitry Gutov <dgutov@yandex.ru>
Define and use ruby-print-result
Closes #74
---
inf-ruby.el | 41 ++++++++++++++++++++++++++++++++---------
1 file changed, 32 insertions(+), 9 deletions(-)
diff --git a/inf-ruby.el b/inf-ruby.el
index 63e3db49a9..08972b1f40 100755
--- a/inf-ruby.el
+++ b/inf-ruby.el
@@ -341,9 +341,9 @@ Must not contain ruby meta characters.")
(defconst ruby-eval-separator "")
-(defun ruby-send-region (start end)
+(defun ruby-send-region (start end &optional print)
"Send the current region to the inferior Ruby process."
- (interactive "r")
+ (interactive "r\nP")
(let (term (file (or buffer-file-name (buffer-name))) line)
(save-excursion
(save-restriction
@@ -365,7 +365,28 @@ Must not contain ruby meta characters.")
term inf-ruby-eval-binding
file line))
(comint-send-region (inf-ruby-proc) start end)
- (comint-send-string (inf-ruby-proc) (concat "\n" term "\n"))))
+ (comint-send-string (inf-ruby-proc) (concat "\n" term "\n"))
+ (when print (ruby-print-result))))
+
+(defun ruby-print-result ()
+ "Print the result of the last evaluation in the current buffer."
+ (let ((proc (inf-ruby-proc)))
+ (insert
+ (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)))
+ (accept-process-output proc))
+ (re-search-backward inf-ruby-prompt-pattern)
+ (or (re-search-forward " => " (car comint-last-prompt) t)
+ ;; Evaluation seems to have failed.
+ ;; Try to extract the error string.
+ (let* ((inhibit-field-text-motion t)
+ (s (buffer-substring-no-properties (point)
(line-end-position))))
+ (while (string-match inf-ruby-prompt-pattern s)
+ (setq s (replace-match "" t t s)))
+ (error "%s" s)))
+ (buffer-substring-no-properties (point) (line-end-position))))))
(defun ruby-send-definition ()
"Send the current definition to the inferior Ruby process."
@@ -376,20 +397,22 @@ Must not contain ruby meta characters.")
(ruby-beginning-of-defun)
(ruby-send-region (point) end))))
-(defun ruby-send-last-sexp ()
+(defun ruby-send-last-sexp (&optional print)
"Send the previous sexp to the inferior Ruby process."
- (interactive)
- (ruby-send-region (save-excursion (ruby-backward-sexp) (point)) (point)))
+ (interactive "P")
+ (ruby-send-region (save-excursion (ruby-backward-sexp) (point)) (point))
+ (when print (ruby-print-result)))
-(defun ruby-send-block ()
+(defun ruby-send-block (&optional print)
"Send the current block to the inferior Ruby process."
- (interactive)
+ (interactive "P")
(save-excursion
(ruby-end-of-block)
(end-of-line)
(let ((end (point)))
(ruby-beginning-of-block)
- (ruby-send-region (point) end))))
+ (ruby-send-region (point) end)))
+ (when print (ruby-print-result)))
(defvar ruby-last-ruby-buffer nil
"The last buffer we switched to `inf-ruby' from.")
- [nongnu] elpa/inf-ruby e8cd8c4a28 076/265: Touch up README, docstrings and comments, (continued)
- [nongnu] elpa/inf-ruby e8cd8c4a28 076/265: Touch up README, docstrings and comments, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 24c08fca2a 152/265: Fix the previous commit, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 171c4e9e38 139/265: Update subheaders, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 96408b9cad 149/265: Update MELPA URL, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby c353603f1f 140/265: Merge pull request #68 from Trevoke/patch-1, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 0885009c11 012/265: Version 2.2, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 37bae51429 015/265: Replace pointless setfs with setqs., ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 80a1c2c3d2 031/265: Fix commit 'Store non-whitespace input in the REPL history, ...', ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 0b27477d11 166/265: Tweak auto-enter and auto-exit to work better (or at all), ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby db89398caa 173/265: Recognize byebug prompt, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby beb39ad5af 148/265: Define and use ruby-print-result,
ELPA Syncer <=
- [nongnu] elpa/inf-ruby 5c73e1a79c 143/265: Use INSIDE_EMACS, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 57b3419be3 175/265: Allow single quoted gemspec name, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 73e2142a99 194/265: Add new option inf-ruby-console-environment, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 7aa37e9154 199/265: Add ruby-send-line function, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 05984b3d24 201/265: inf-ruby-console-read-directory: Fix for predicates with wildcards, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 401f191d53 045/265: Touch up docstrings, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby d308394e7a 041/265: inf-ruby-output-filter: Ignore empty strings, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 5fa2f80d4e 057/265: inf-ruby-completions: Pass _pry_ when it's defined, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 2c28bc9f57 060/265: inf-ruby-prompt-format: Include whitespace after rdb prompt, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby c5d2178f17 072/265: Add a basic README, ELPA Syncer, 2022/07/09