I want to print coloured text in the minibuffer and in the Messages. Can this be done and how?
1 Answer
message
shows message strings with whatever properties you've given them. The function for adding text properties to a string is propertize
.
See C-h f propertize
and the Elisp manual, node Changing Properties.
(message "%s" (propertize "My message" 'face 'highlight))
Or:
(message "My %s" (propertize "message" 'face 'highlight))
-
(message "%s" (propertize "Counting bracketing marks " 'face 'highlight))
did not colour the string. How con I pass a hex-code instead.– VeakMar 18, 2022 at 19:52 -
Yes, it does. How are you evaluating it? Select it and use
eval-region
. Or put it in a function and call the function. If you still don't see highlighting in the message then try withemacs -Q
(no init file).– DrewMar 18, 2022 at 19:54 -
I want to put it in a function and call the message that will display in colour in the mini-buffer and in the
*Messages*
buffer.– VeakMar 18, 2022 at 21:23 -
I have emacs use bold, so that highlight would not show any difference in how text is displayed.– VeakMar 19, 2022 at 1:31
-
You asked about function
message
, which shows text in the echo area. Buffer*Messages*
doesn't display the message; instead, the string is printed there. Printing doesn't show text properties. As for "that highlight": use any face you want, instead of facehighlight
. You don't say what "I have emacs use bold" means. But if you're doing something that inhibits showing faces, well then, you won't see them, will you?– DrewMar 19, 2022 at 1:44