From: Jim Porter Date: Sun, 26 Mar 2023 23:55:24 +0000 (-0700) Subject: When waiting for a process in Eshell, consult its status X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b9917f11521d47426330d79c65f9726c8fd7f8f7;p=emacs.git When waiting for a process in Eshell, consult its status This should be functionally the same as the previous implementation in most cases (which consulted its membership in 'eshell-process-list'), but is more flexible. It's now possible to wait for processes that aren't in 'eshell-process-list'. Additionally, use 'process-live-p' instead of examining 'process-status' in a few places. This is simpler, and a bit more correct too for certain types of processes (though it likely doesn't matter in practice). * lisp/eshell/esh-io.el (eshell-close-target) (eshell-output-object-to-target) * lisp/eshell/esh-proc.el (eshell-process-interact): Use 'process-live-p'. (eshell-wait-for-process): Use 'process-live-p' and remove reference to 'eshell-process-list'. --- diff --git a/lisp/eshell/esh-io.el b/lisp/eshell/esh-io.el index c9d87c650d5..c07f871dd37 100644 --- a/lisp/eshell/esh-io.el +++ b/lisp/eshell/esh-io.el @@ -597,7 +597,7 @@ If status is nil, prompt before killing." ;; details. (catch 'done (dotimes (_ (if (process-tty-name target 'stdin) 3 1)) - (unless (eq (process-status target) 'run) + (unless (process-live-p target) (throw 'done nil)) (process-send-eof target)))) @@ -650,8 +650,7 @@ Returns what was actually sent, or nil if nothing was sent.") ;; If `process-send-string' raises an error and the process has ;; finished, treat it as a broken pipe. Otherwise, just ;; re-throw the signal. - (if (memq (process-status target) - '(run stop open closed)) + (if (process-live-p target) (signal (car err) (cdr err)) (signal 'eshell-pipe-broken (list target))))) object) diff --git a/lisp/eshell/esh-proc.el b/lisp/eshell/esh-proc.el index 00e0c8014e1..f2d20b4cded 100644 --- a/lisp/eshell/esh-proc.el +++ b/lisp/eshell/esh-proc.el @@ -157,17 +157,14 @@ The signals which will cause this to happen are matched by (eshell-reset))) (defun eshell-wait-for-process (&rest procs) - "Wait until PROC has successfully completed." - (while procs - (let ((proc (car procs))) - (when (eshell-processp proc) - ;; NYI: If the process gets stopped here, that's bad. - (while (assq proc eshell-process-list) - (if (input-pending-p) - (discard-input)) - (sit-for eshell-process-wait-seconds - eshell-process-wait-milliseconds)))) - (setq procs (cdr procs)))) + "Wait until PROCS have successfully completed." + (dolist (proc procs) + (when (eshell-processp proc) + (while (process-live-p proc) + (when (input-pending-p) + (discard-input)) + (sit-for eshell-process-wait-seconds + eshell-process-wait-milliseconds))))) (defalias 'eshell/wait #'eshell-wait-for-process) @@ -506,16 +503,14 @@ If ALL is non-nil, background processes will be interacted with as well. If QUERY is non-nil, query the user with QUERY before calling FUNC." (let (defunct result) (dolist (entry eshell-process-list) - (if (and (memq (process-status (car entry)) - '(run stop open closed)) + (if (and (process-live-p (car entry)) (or all (not (cdr entry))) (or (not query) (y-or-n-p (format-message query (process-name (car entry)))))) (setq result (funcall func (car entry)))) - (unless (memq (process-status (car entry)) - '(run stop open closed)) + (unless (process-live-p (car entry)) (setq defunct (cons entry defunct)))) ;; clean up the process list; this can get dirty if an error ;; occurred that brought the user into the debugger, and then they