emacs-diffs
[Top][All Lists]
Advanced

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

master d069361 2/3: Make `eshell-command' also work when asynchronous


From: Lars Ingebrigtsen
Subject: master d069361 2/3: Make `eshell-command' also work when asynchronous
Date: Fri, 27 Aug 2021 11:15:24 -0400 (EDT)

branch: master
commit d0693617b8dd986475cd7b96f20cdf2bfd27751e
Author: Thierry Volpiatto <thievol@posteo.net>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Make `eshell-command' also work when asynchronous
    
    * lisp/eshell/esh-cmd.el (eshell-eval-command): Make asynchronous
    `eshell-command' work (e.g. `M-x eshell-command RET sleep 10 &')
    (bug#50209).
---
 lisp/eshell/esh-cmd.el | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el
index daca035..90a8f85 100644
--- a/lisp/eshell/esh-cmd.el
+++ b/lisp/eshell/esh-cmd.el
@@ -923,10 +923,10 @@ at the moment are:
 (defun eshell-eval-command (command &optional input)
   "Evaluate the given COMMAND iteratively."
   (if eshell-current-command
-      ;; we can just stick the new command at the end of the current
-      ;; one, and everything will happen as it should
+      ;; We can just stick the new command at the end of the current
+      ;; one, and everything will happen as it should.
       (setcdr (last (cdr eshell-current-command))
-             (list `(let ((here (and (eobp) (point))))
+              (list `(let ((here (and (eobp) (point))))
                        ,(and input
                              `(insert-and-inherit ,(concat input "\n")))
                        (if here
@@ -937,14 +937,20 @@ at the moment are:
            (erase-buffer)
            (insert "command: \"" input "\"\n")))
     (setq eshell-current-command command)
-    (let ((delim (catch 'eshell-incomplete
-                  (eshell-resume-eval))))
-      ;; On systems that don't support async subprocesses, eshell-resume
-      ;; can return t.  Don't treat that as an error.
-      (if (listp delim)
-         (setq delim (car delim)))
-      (if (and delim (not (eq delim t)))
-         (error "Unmatched delimiter: %c" delim)))))
+    (let* ((delim (catch 'eshell-incomplete
+                    (eshell-resume-eval)))
+           (val (car-safe delim)))
+      ;; If the return value of `eshell-resume-eval' is wrapped in a
+      ;; list, it indicates that the command was run asynchronously.
+      ;; In that case, unwrap the value before checking the delimiter
+      ;; value.
+      (if (and val
+               (not (processp val))
+               (not (eq val t)))
+          (error "Unmatched delimiter: %S" val)
+        ;; Eshell-command expect a list like (<process>) to know if the
+        ;; command should be async or not.
+        (or (and (processp val) delim) val)))))
 
 (defun eshell-resume-command (proc status)
   "Resume the current command when a process ends."



reply via email to

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