0

I want to print coloured text in the minibuffer and in the Messages. Can this be done and how?

1
  • Please do not post the same question to both StackOverflow and emacs.SE. Please delete one and keep the other. (And please consider using the same user name for both sites.) Thx.
    – Drew
    Mar 19, 2022 at 16:20

1 Answer 1

0

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))
11
  • (message "%s" (propertize "Counting bracketing marks " 'face 'highlight)) did not colour the string. How con I pass a hex-code instead.
    – Veak
    Mar 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 with emacs -Q (no init file).
    – Drew
    Mar 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.
    – Veak
    Mar 18, 2022 at 21:23
  • I have emacs use bold, so that highlight would not show any difference in how text is displayed.
    – Veak
    Mar 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 face highlight. 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?
    – Drew
    Mar 19, 2022 at 1:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.