There are two versions of function (inhibit-sentinel-messages FUN &rest ARGS)
defined in Section Code of inhibit-sentinel-messages of this answer. The first version wraps all sentinels started in FUN
with set-process-sentinel
into let
blocks with inhibit-message t
. The second version avoids sentinel messages completely by temporarily advising message
with ignore
.
You can use inhibit-sentinel-messages
like so:
(inhibit-sentinel-messages #'async-shell-command "echo test")
If you also want to hide the *Async Shell Command*
buffer you can use display-buffer-alist
let-bound as follows:
(let ((display-buffer-alist (cons '("\\`\\*Async Shell Command\\*\\'" display-buffer-no-window) display-buffer-alist)))
(inhibit-sentinel-messages #'async-shell-command "echo test"))
If you want to suppress sentinel messages in idle timers you need to use inhibit-sentinel-messages
in the body of the timer function.
Example:
(setq my-counter 0)
(setq my-timer (run-with-idle-timer
10 t
(lambda ()
(inhibit-sentinel-messages
#'async-shell-command (format "echo test%d" (cl-incf my-counter))))))
Code of inhibit-sentinel-messages
Binding inhibit-message
to t
This code avoids displaying the sentinel messages in the echo area. The sentinel messages are still output to the *Messages*
buffer.
(defun inhibit-sentinel-messages (fun &rest args)
"Inhibit messages in all sentinels started by fun."
(cl-letf* ((old-set-process-sentinel (symbol-function 'set-process-sentinel))
((symbol-function 'set-process-sentinel)
(lambda (process sentinel)
(funcall
old-set-process-sentinel
process
`(lambda (&rest args)
(let ((inhibit-message t))
(apply (quote ,sentinel) args)))))))
(apply fun args)))
Temporarily advising message
to ignore
This code avoids the generation of sentinel messages completely.
(defun inhibit-sentinel-messages (fun &rest args)
"Inhibit messages in all sentinels started by fun."
(cl-letf* ((old-set-process-sentinel (symbol-function 'set-process-sentinel))
((symbol-function 'set-process-sentinel)
(lambda (process sentinel)
(funcall
old-set-process-sentinel
process
`(lambda (&rest args)
(cl-letf (((symbol-function 'message) #'ignore))
(apply (quote ,sentinel) args)))))))
(apply fun args)))