]> git.eshelyaron.com Git - emacs.git/commitdiff
Don't emit a prompt in Eshell when a background command is killed
authorJim Porter <jporterbugs@gmail.com>
Tue, 9 Jul 2024 17:45:35 +0000 (10:45 -0700)
committerEshel Yaron <me@eshelyaron.com>
Fri, 12 Jul 2024 18:00:05 +0000 (20:00 +0200)
* lisp/eshell/esh-cmd.el (eshell-resume-command): Check for
background-ness before resetting the prompt.

* test/lisp/eshell/esh-cmd-tests.el
(esh-cmd-test/background/simple-command): Make the regexp a bit
stricter.
(esh-cmd-test/background/kill): New test.

(cherry picked from commit 0de0056fd6b3b70dde54884db5d9ffc013c49efc)

lisp/eshell/esh-cmd.el
test/lisp/eshell/esh-cmd-tests.el

index b936f68a57acf3739df124f13b444a61151c55a0..c8579c83405ae6eb79695cb5881adc8c9d5fb960 100644 (file)
@@ -1030,6 +1030,9 @@ process(es) in a cons cell like:
 PROC is the process that invoked this from its sentinel, and
 STATUS is its status."
   (when proc
+    ;; Iterate over all the commands associated with this process.  Each
+    ;; element is a list of the form (BACKGROUND FORM PROCESSES) (see
+    ;; `eshell-add-command').
     (dolist (command (eshell-commands-for-process proc))
       (unless (seq-some #'eshell-process-active-p (nth 2 command))
         (setf (nth 2 command) nil) ; Clear processes from command.
@@ -1040,8 +1043,12 @@ STATUS is its status."
                  (not (string-match eshell-reset-signals status)))
             (eshell-resume-eval command)
           (eshell-remove-command command)
-          (declare-function eshell-reset "esh-mode" (&optional no-hooks))
-          (eshell-reset))))))
+          ;; Check if the command we just aborted is marked as a
+          ;; background command.  If not, we need to reset the prompt so
+          ;; the user can enter another command.
+          (unless (car command)
+            (declare-function eshell-reset "esh-mode" (&optional no-hooks))
+            (eshell-reset)))))))
 
 (defun eshell-resume-eval (command)
   "Destructively evaluate a COMMAND which may need to be deferred.
index 70e1901c169ebb7cd15fa708bc1ae354aa83a481..d8124a19af68ea988f7a804f1fb1247ae075d561 100644 (file)
@@ -113,7 +113,7 @@ bug#59469."
     (with-temp-eshell
      (eshell-match-command-output
       (format "*echo hi > #<%s> &" bufname)
-      (rx "[echo" (? ".exe") "] " (+ digit) "\n"))
+      (rx bos "[echo" (? ".exe") "] " (+ digit) "\n"))
      (eshell-wait-for-subprocess t))
     (should (equal (buffer-string) "hi\n"))))
 
@@ -129,6 +129,18 @@ bug#59469."
      (eshell-wait-for-subprocess t))
     (should (equal (buffer-string) "olleh\n"))))
 
+(ert-deftest esh-cmd-test/background/kill ()
+  "Make sure that a background command that gets killed doesn't emit a prompt."
+  (skip-unless (executable-find "sleep"))
+  (let ((background-message (rx bos "[sleep" (? ".exe") "] " (+ digit) "\n")))
+    (with-temp-eshell
+      (eshell-match-command-output "*sleep 10 &" background-message)
+      (kill-process (caar eshell-process-list))
+      (eshell-wait-for-subprocess t)
+      ;; Ensure we didn't emit another prompt after killing the
+      ;; background process.
+      (should (eshell-match-output background-message)))))
+
 \f
 ;; Lisp forms