]> git.eshelyaron.com Git - emacs.git/commitdiff
When waiting for a process in Eshell, consult its status
authorJim Porter <jporterbugs@gmail.com>
Sun, 26 Mar 2023 23:55:24 +0000 (16:55 -0700)
committerJim Porter <jporterbugs@gmail.com>
Thu, 24 Aug 2023 05:18:52 +0000 (22:18 -0700)
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'.

lisp/eshell/esh-io.el
lisp/eshell/esh-proc.el

index c9d87c650d51e1f5c94e86beeda5e2cef53e2b3f..c07f871dd37bef4170c46989f052d752e132eb06 100644 (file)
@@ -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)
index 00e0c8014e155b11779f74dde56e3bd0d31d658f..f2d20b4cdedd6a98a7d7e4e32ed919a66913fabe 100644 (file)
@@ -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