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

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

[nongnu] elpa/geiser e4175e7b2c 2/2: New function geiser-eval-region/wai


From: ELPA Syncer
Subject: [nongnu] elpa/geiser e4175e7b2c 2/2: New function geiser-eval-region/wait
Date: Wed, 29 Dec 2021 11:58:15 -0500 (EST)

branch: elpa/geiser
commit e4175e7b2c012fbefdabad1ee4e96ff8cc25df4e
Author: jao <jao@gnu.org>
Commit: jao <jao@gnu.org>

    New function geiser-eval-region/wait
---
 elisp/geiser-debug.el | 14 ++++++++++++++
 elisp/geiser-mode.el  | 10 +++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/elisp/geiser-debug.el b/elisp/geiser-debug.el
index f5b98a3a7d..f761c8b997 100644
--- a/elisp/geiser-debug.el
+++ b/elisp/geiser-debug.el
@@ -286,6 +286,12 @@ buffer.")
     str))
 
 (defun geiser-debug--send-region (compile start end and-go wrap &optional 
nomsg)
+  "Evaluate (or COMPILE) the region delimited by START and END.
+The result of the evaluation is reported asynchronously, so this
+call is not blocking. If AND-GO is t, also jump to the repl
+buffer.  If WRAP is t, the region's content is wrapped in a begin
+form.  The flag NOMSG can be used to avoid reporting of the
+result in the minibuffer."
   (let* ((str (buffer-substring-no-properties start end))
          (wrapped (if wrap (geiser-debug--wrap-region str) str))
          (code `(,(if compile :comp :eval) (:scm ,wrapped)))
@@ -306,6 +312,14 @@ buffer.")
                    (geiser-debug--display-retort scstr ret res)))))
     (geiser-eval--send code cont (current-buffer))))
 
+(defun geiser-debug--send-region/wait (compile start end timeout)
+  "Synchronous version of `geiser-debug--send-region', waiting and returning 
its result."
+  (let* ((str (buffer-substring-no-properties start end))
+         (wrapped (geiser-debug--wrap-region str))
+         (code `(,(if compile :comp :eval) (:scm ,wrapped))))
+    (message "evaluating: %s" code)
+    (geiser-eval--send/wait code timeout)))
+
 (defun geiser-debug--expand-region (start end all wrap)
   (let* ((str (buffer-substring-no-properties start end))
          (wrapped (if wrap (geiser-debug--wrap-region str) str))
diff --git a/elisp/geiser-mode.el b/elisp/geiser-mode.el
index b1df1b6ada..9ea4d605c0 100644
--- a/elisp/geiser-mode.el
+++ b/elisp/geiser-mode.el
@@ -110,7 +110,9 @@ individual sexps."
 With prefix, goes to the REPL buffer afterwards (as
 `geiser-eval-region-and-go').  The evaluation is performed
 asynchronously: this function's return value can be used to wait
-for its completion using `geiser-eval-wait'."
+for its completion using `geiser-eval-wait'.  See also
+`geiser-eval-region/wait' if you just need to eval a region
+programmatically in a synchronous way."
   (interactive "rP")
   (save-restriction
     (narrow-to-region start end)
@@ -122,6 +124,12 @@ for its completion using `geiser-eval-wait'."
                              (not raw)
                              nomsg))
 
+(defun geiser-eval-region/wait (start end &optional timeout)
+  "Like `geiser-eval-region', but waiting for the evaluation to finish.
+Returns its raw result, rather than displaying it. TIMEOUT is the
+number of seconds to wait for the evaluation to finish."
+  (geiser-debug--send-region/wait nil start end (* 1000 (or timeout 10))))
+
 (defun geiser-eval-region-and-go (start end)
   "Eval the current region in the Geiser REPL and visit it afterwads."
   (interactive "r")



reply via email to

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