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.

Drew
  • 29,895
  • 7
  • 74
  • 104
Aemon Cannon
  • 440
  • 3
  • 8

1 Answers1

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.

huaiyuan
  • 26,129
  • 5
  • 57
  • 63
  • 1
    `(defun lawlist-message (input) (interactive) (message (propertize input 'face 'font-lock-warning-face)))` – lawlist Jan 25 '14 at 22:25
  • 1
    Is there a way that the color are preserved in the `*Messages*` buffer? – AdrieanKhisbe Jul 16 '14 at 20:40
  • 8
    If you see the `#("foo" 0 3 (face (:foreground "red")))`, instead of showing a red `foo`, see here for [an explanation](http://emacs.stackexchange.com/a/2332/11060), 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. – Suzanne Soy Feb 09 '16 at 11:36