In Emacs, how do I display a message in the minibuffer with font face properties?
Asked Answered
T

1

22

I want to display a colored string of text in the minibuffer, but when I use the 'message' function, the text-properties of are stripped.

Thiazole answered 30/4, 2010 at 5:21 Comment(0)
T
30

Works for me:

(message "%s" (propertize "foo" 'face '(:foreground "red")))

You probably had (message (propertize ...)), which interprets the propertized string as a format control string, hence stripped of its properties.

Tonometer answered 30/4, 2010 at 7:10 Comment(3)
(defun lawlist-message (input) (interactive) (message (propertize input 'face 'font-lock-warning-face)))Undry
Is there a way that the color are preserved in the *Messages* buffer?Gorcock
If you see the #("foo" 0 3 (face (:foreground "red"))), instead of showing a red foo, see here for an explanation, the reason is that the message is displayed, but then the result of the expression is printed, which hides the message. Putting it in an (interactive) makes it work as expected.Ribble

© 2022 - 2024 — McMap. All rights reserved.