* 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.
(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)
"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)
(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
(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
(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)))
"\\`\\'"))
(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\""