[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/geiser f5e7004bf2 3/3: New helper, geiser-eval-wait, to fa
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/geiser f5e7004bf2 3/3: New helper, geiser-eval-wait, to facilitate synchronous evaluations |
Date: |
Mon, 27 Dec 2021 11:58:08 -0500 (EST) |
branch: elpa/geiser
commit f5e7004bf2f5af381dbf3387108cde210a190733
Author: jao <jao@gnu.org>
Commit: jao <jao@gnu.org>
New helper, geiser-eval-wait, to facilitate synchronous evaluations
This should address, for instance, issue #30
---
elisp/geiser-connection.el | 24 +++++++++++++++---------
elisp/geiser-mode.el | 13 ++++++++++++-
2 files changed, 27 insertions(+), 10 deletions(-)
diff --git a/elisp/geiser-connection.el b/elisp/geiser-connection.el
index 745aa14d96..87f5f7f498 100644
--- a/elisp/geiser-connection.el
+++ b/elisp/geiser-connection.el
@@ -260,19 +260,25 @@
(when (process-live-p proc)
(interrupt-process proc))))
+(defun geiser-con--wait (req timeout)
+ "Wait for the given request REQ to finish, up to TIMEOUT secs, returning its
result."
+ (let* ((con (geiser-con--request-connection req))
+ (id (geiser-con--request-id req))
+ (timeout (/ (or timeout geiser-connection-timeout) 1000.0))
+ (step (/ timeout 10)))
+ (with-timeout (timeout (geiser-con--request-deactivate req))
+ (condition-case nil
+ (while (and (geiser-con--connection-process con)
+ (not (geiser-con--connection-completed-p con id)))
+ (accept-process-output proc step))
+ (error (geiser-con--request-deactivate req))))))
+
(defun geiser-con--send-string/wait (con str cont &optional timeout sbuf)
(save-current-buffer
(let ((proc (and con (geiser-con--connection-process con))))
(unless proc (error "Geiser connection not active"))
- (let* ((req (geiser-con--send-string con str cont sbuf))
- (id (geiser-con--request-id req))
- (timeout (/ (or timeout geiser-connection-timeout) 1000.0)))
- (with-timeout (timeout (geiser-con--request-deactivate req))
- (condition-case nil
- (while (and (geiser-con--connection-process con)
- (not (geiser-con--connection-completed-p con id)))
- (accept-process-output proc (/ timeout 10)))
- (error (geiser-con--request-deactivate req))))))))
+ (let ((req (geiser-con--send-string con str cont sbuf)))
+ (geiser-con--wait req timeout)))))
(provide 'geiser-connection)
diff --git a/elisp/geiser-mode.el b/elisp/geiser-mode.el
index 1e5df0bb61..06e6655973 100644
--- a/elisp/geiser-mode.el
+++ b/elisp/geiser-mode.el
@@ -95,11 +95,22 @@ result is an error msg."
(push-mark)
(goto-char (point-max)))
+(defun geiser-eval-wait (req timeout)
+ "Use REQ, the result of computing an evaluation, to wait for its result.
+
+TIMEOUT is the number of seconds to wait for evaluation
+completion. Functions returning a waitable REQ are
+`geiser-eval-region' and its derivatives evaluating buffers or
+individual sexps."
+ (geiser-con--wait req timeout))
+
(defun geiser-eval-region (start end &optional and-go raw nomsg)
"Eval the current region in the Geiser REPL.
With prefix, goes to the REPL buffer afterwards (as
-`geiser-eval-region-and-go')"
+`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'."
(interactive "rP")
(save-restriction
(narrow-to-region start end)