diff options
| author | Thierry Volpiatto | 2021-08-27 17:01:21 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2021-08-27 17:15:17 +0200 |
| commit | d0693617b8dd986475cd7b96f20cdf2bfd27751e (patch) | |
| tree | 6b25f4d8c63d591e7addd383fc5bad689b9d8db1 | |
| parent | 0d45ad99da4c7ba0a9928aab91ffa0ccdee5bf73 (diff) | |
| download | emacs-d0693617b8dd986475cd7b96f20cdf2bfd27751e.tar.gz emacs-d0693617b8dd986475cd7b96f20cdf2bfd27751e.zip | |
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).
| -rw-r--r-- | lisp/eshell/esh-cmd.el | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el index daca035ea49..90a8f85665a 100644 --- a/lisp/eshell/esh-cmd.el +++ b/lisp/eshell/esh-cmd.el | |||
| @@ -923,10 +923,10 @@ at the moment are: | |||
| 923 | (defun eshell-eval-command (command &optional input) | 923 | (defun eshell-eval-command (command &optional input) |
| 924 | "Evaluate the given COMMAND iteratively." | 924 | "Evaluate the given COMMAND iteratively." |
| 925 | (if eshell-current-command | 925 | (if eshell-current-command |
| 926 | ;; we can just stick the new command at the end of the current | 926 | ;; We can just stick the new command at the end of the current |
| 927 | ;; one, and everything will happen as it should | 927 | ;; one, and everything will happen as it should. |
| 928 | (setcdr (last (cdr eshell-current-command)) | 928 | (setcdr (last (cdr eshell-current-command)) |
| 929 | (list `(let ((here (and (eobp) (point)))) | 929 | (list `(let ((here (and (eobp) (point)))) |
| 930 | ,(and input | 930 | ,(and input |
| 931 | `(insert-and-inherit ,(concat input "\n"))) | 931 | `(insert-and-inherit ,(concat input "\n"))) |
| 932 | (if here | 932 | (if here |
| @@ -937,14 +937,20 @@ at the moment are: | |||
| 937 | (erase-buffer) | 937 | (erase-buffer) |
| 938 | (insert "command: \"" input "\"\n"))) | 938 | (insert "command: \"" input "\"\n"))) |
| 939 | (setq eshell-current-command command) | 939 | (setq eshell-current-command command) |
| 940 | (let ((delim (catch 'eshell-incomplete | 940 | (let* ((delim (catch 'eshell-incomplete |
| 941 | (eshell-resume-eval)))) | 941 | (eshell-resume-eval))) |
| 942 | ;; On systems that don't support async subprocesses, eshell-resume | 942 | (val (car-safe delim))) |
| 943 | ;; can return t. Don't treat that as an error. | 943 | ;; If the return value of `eshell-resume-eval' is wrapped in a |
| 944 | (if (listp delim) | 944 | ;; list, it indicates that the command was run asynchronously. |
| 945 | (setq delim (car delim))) | 945 | ;; In that case, unwrap the value before checking the delimiter |
| 946 | (if (and delim (not (eq delim t))) | 946 | ;; value. |
| 947 | (error "Unmatched delimiter: %c" delim))))) | 947 | (if (and val |
| 948 | (not (processp val)) | ||
| 949 | (not (eq val t))) | ||
| 950 | (error "Unmatched delimiter: %S" val) | ||
| 951 | ;; Eshell-command expect a list like (<process>) to know if the | ||
| 952 | ;; command should be async or not. | ||
| 953 | (or (and (processp val) delim) val))))) | ||
| 948 | 954 | ||
| 949 | (defun eshell-resume-command (proc status) | 955 | (defun eshell-resume-command (proc status) |
| 950 | "Resume the current command when a process ends." | 956 | "Resume the current command when a process ends." |