emacs-diffs
[Top][All Lists]
Advanced

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

master 8f2cfe15a72 1/2: Don't print subjob messages when running an Eshe


From: Jim Porter
Subject: master 8f2cfe15a72 1/2: Don't print subjob messages when running an Eshell script in the background
Date: Mon, 2 Oct 2023 23:56:15 -0400 (EDT)

branch: master
commit 8f2cfe15a72a0c440909faa50a9c436931dcf85e
Author: Jim Porter <jporterbugs@gmail.com>
Commit: Jim Porter <jporterbugs@gmail.com>

    Don't print subjob messages when running an Eshell script in the background
    
    * lisp/eshell/esh-proc.el (eshell-subjob-messages): New variable...
    (eshell-record-process-object)
    (eshell-remove-process-entry): ... check it.
    
    * lisp/eshell/em-script.el (eshell-source-file): Set
    'eshell-subjob-messages' to nil.
    
    * lisp/eshell/esh-cmd.el (eshell-do-subjob): Set
    'eshell-subjob-messages' to t.
    
    * test/lisp/eshell/em-script-tests.el
    (em-script-test/source-script/background): New test.
---
 lisp/eshell/em-script.el            |  7 ++++++-
 lisp/eshell/esh-cmd.el              |  5 ++++-
 lisp/eshell/esh-proc.el             | 18 +++++++++++-------
 test/lisp/eshell/em-script-tests.el | 13 +++++++++++++
 4 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/lisp/eshell/em-script.el b/lisp/eshell/em-script.el
index 9f6f720b8b0..3a4c315ad15 100644
--- a/lisp/eshell/em-script.el
+++ b/lisp/eshell/em-script.el
@@ -94,7 +94,12 @@ Comments begin with `#'."
       (setq cmd `(eshell-as-subcommand ,cmd)))
     (throw 'eshell-replace-command
            `(let ((eshell-command-name ',file)
-                  (eshell-command-arguments ',args))
+                  (eshell-command-arguments ',args)
+                  ;; Don't print subjob messages by default.
+                  ;; Otherwise, if this function was called as a
+                  ;; subjob, then *all* commands in the script would
+                  ;; print start/stop messages.
+                  (eshell-subjob-messages nil))
               ,cmd))))
 
 (defun eshell/source (&rest args)
diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el
index 1d828bd7f82..fc7d54a758d 100644
--- a/lisp/eshell/esh-cmd.el
+++ b/lisp/eshell/esh-cmd.el
@@ -742,7 +742,10 @@ if none)."
   "Evaluate a command OBJECT as a subjob.
 We indicate that the process was run in the background by returning it
 ensconced in a list."
-  `(let ((eshell-current-subjob-p t))
+  `(let ((eshell-current-subjob-p t)
+         ;; Print subjob messages.  This could have been cleared
+         ;; (e.g. by `eshell-source-file', which see).
+         (eshell-subjob-messages t))
      ,object))
 
 (defmacro eshell-commands (object &optional silent)
diff --git a/lisp/eshell/esh-proc.el b/lisp/eshell/esh-proc.el
index d15e1e7d09b..126c7d0f26e 100644
--- a/lisp/eshell/esh-proc.el
+++ b/lisp/eshell/esh-proc.el
@@ -100,6 +100,8 @@ information, for example."
 (defvar eshell-supports-asynchronous-processes (fboundp 'make-process)
   "Non-nil if Eshell can create asynchronous processes.")
 
+(defvar eshell-subjob-messages t
+  "Non-nil if we should print process start/end messages for subjobs.")
 (defvar eshell-current-subjob-p nil)
 
 (defvar eshell-process-list nil
@@ -243,8 +245,9 @@ The prompt will be set to PROMPT."
 
 (defsubst eshell-record-process-object (object)
   "Record OBJECT as now running."
-  (when (and (eshell-processp object)
-            eshell-current-subjob-p)
+  (when (and eshell-subjob-messages
+             eshell-current-subjob-p
+             (eshell-processp object))
     (require 'esh-mode)
     (declare-function eshell-interactive-print "esh-mode" (string))
     (eshell-interactive-print
@@ -253,11 +256,12 @@ The prompt will be set to PROMPT."
 
 (defun eshell-remove-process-entry (entry)
   "Record the process ENTRY as fully completed."
-  (if (and (eshell-processp (car entry))
-          (cdr entry)
-          eshell-done-messages-in-minibuffer)
-      (message "[%s]+ Done %s" (process-name (car entry))
-              (process-command (car entry))))
+  (when (and eshell-subjob-messages
+             eshell-done-messages-in-minibuffer
+             (eshell-processp (car entry))
+             (cdr entry))
+    (message "[%s]+ Done %s" (process-name (car entry))
+             (process-command (car entry))))
   (setq eshell-process-list
        (delq entry eshell-process-list)))
 
diff --git a/test/lisp/eshell/em-script-tests.el 
b/test/lisp/eshell/em-script-tests.el
index 74328844778..191755dcc3e 100644
--- a/test/lisp/eshell/em-script-tests.el
+++ b/test/lisp/eshell/em-script-tests.el
@@ -63,6 +63,19 @@
         "\\`\\'"))
       (should (equal (buffer-string) "hibye")))))
 
+(ert-deftest em-script-test/source-script/background ()
+  "Test sourcing a script in the background."
+  (skip-unless (executable-find "echo"))
+  (ert-with-temp-file temp-file
+    :text "*echo hi"
+    (eshell-with-temp-buffer bufname "old"
+      (with-temp-eshell
+       (eshell-match-command-output
+        (format "source %s > #<%s> &" temp-file bufname)
+        "\\`\\'")
+       (eshell-wait-for-subprocess t))
+      (should (equal (buffer-string) "hi\n")))))
+
 (ert-deftest em-script-test/source-script/arg-vars ()
   "Test sourcing script with $0, $1, ... variables."
   (ert-with-temp-file temp-file :text "printnl $0 \"$1 $2\""



reply via email to

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