This macro adds support for adding a suffix to messages.
Using advice allows this to be nested, so multiple functions can add their own suffixes which accumulate onto the end.
(defmacro with-temp-advice (fn-orig where fn-advice &rest body)
"Execute BODY with advice temporarily enabled."
`
(let ((fn-advice-var ,fn-advice))
(unwind-protect
(progn
(advice-add ,fn-orig ,where fn-advice-var)
,@body)
(advice-remove ,fn-orig fn-advice-var))))
(defmacro with-message-suffix (suffix &rest body)
"Add text after the message output.
Argument SUFFIX is the text to add at the start of the message.
Optional argument BODY runs with the message suffix."
(declare (indent 1))
`
(with-temp-advice
'message
:around
(lambda (fn-orig arg &rest args)
(apply fn-orig (append (list (concat arg "%s")) args (list ,suffix))))
,@body))
i advice
in the Elisp manual. – Drew Dec 23 '19 at 1:29let
can locally override variables) – ideasman42 Dec 23 '19 at 1:30cl-flet
andcl-letf
to redefine locally. – Drew Dec 23 '19 at 2:06cl-letf
seems to be what I'm looking for. – ideasman42 Dec 23 '19 at 22:31