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)
(declare (indent 3))
(let ((function-var (gensym)))
`(let ((,function-var ,fn-advice))
(unwind-protect
(progn
(advice-add ,fn-orig ,where ,function-var)
,@body)
(advice-remove ,fn-orig ,function-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.let
can locally override variables)cl-flet
andcl-letf
to redefine locally.cl-letf
seems to be what I'm looking for.