The function in question is image-mode
, and this seems to do what you want (if a little inelegantly):
(defun my/image-unwanted-message-p (msg &rest objects)
"Return non-nil if MSG is unwanted.
For these purposes, a MSG is unwanted if (after formatting) it is
exactly the string \"Type C-c C-c to view the image as text.\"."
(let ((msg (apply #'format (cons msg objects))))
(string-equal msg "Type C-c C-c to view the image as text.")))
(defun my/image-suppress-messages (fn)
"Suppress unwanted `message' calls in FN."
(my/with-advice
((#'message :before-until #'my/image-unwanted-message-p))
(funcall fn)))
(advice-add #'image-mode :around #'my/image-suppress-messages)
Here my/with-advice
is this macro that I wrote for a previous problem; it's proven to be very handy for a lot of different tasks. I'm using it here because I'm a little leery about applying permanent advice to something as ubiquitous as message
, even if that advice doesn't do anything most of the time.
(defmacro my/with-advice (adlist &rest body)
"Execute BODY with temporary advice in ADLIST.
Each element of ADLIST should be a list of the form
(SYMBOL WHERE FUNCTION [PROPS])
suitable for passing to `advice-add'. The BODY is wrapped in an
`unwind-protect' form, so the advice will be removed even in the
event of an error or nonlocal exit."
(declare (debug ((&rest (&rest form)) body))
(indent 1))
`(progn
,@(mapcar (lambda (adform)
(cons 'advice-add adform))
adlist)
(unwind-protect (progn ,@body)
,@(mapcar (lambda (adform)
`(advice-remove ,(car adform) ,(nth 2 adform)))
adlist))))
Note that the manual cautions not to advise primitives (including message
), but I think it's okay here because (1) all the calls we want to suppress are from lisp anyway; (2) any extraneous calls should pass through transparently; and (3) the advice machinery can't be calling message
here, because you'd be getting messages about it.
image-mode
. But this answer seems solved now, but thanks for your help.