You can't with message
. Having looked at the internals of message
, only the raw char* is given to the function that actually logs the text, all text properties are lost.
You can hack your way around this by writing a function that:
calls message
with message-log-max
let-bound to nil so that it won't log to *Messages*
manually inserts the propertized string at the end of the messages buffer by let-binding inhibit-read-only
to t
in the message buffer.
Here is an implementation:
(defun my-message (format &rest args)
"Acts like `message' but preserves string properties in the *Messages* buffer."
(let ((message-log-max nil))
(apply 'message format args))
(with-current-buffer (get-buffer "*Messages*")
(save-excursion
(goto-char (point-max))
(let ((inhibit-read-only t))
(unless (zerop (current-column)) (insert "\n"))
(insert (apply 'format format args))
(insert "\n")))))