Emacs Asked on December 11, 2021
I have:
(setq mode-line-end-spaces "string")
That displays string
in the mode-line.
How can I get string
in red there?
@NickD provided a good answer: use a face.
OP's comment to Nick's answer says that he'll try to write a function that, given a string, returns a propertized string. Such functions already exist: propertize
does that, and so does add-face-text-property
.
For example:
(setq ss (propertize "abcde" 'face '(:foreground "red")))
or
(setq ss "abcde")
(add-face-text-property 0 (length ss) '(:foreground "red") nil ss)
Answered by Drew on December 11, 2021
You need to create a string with the appropriate face. You do that by attaching a face
text property to the string, giving it value of some face (predefined or defined for the specific purpose - you can look at all the predefined faces with M-x list-faces-display
and pick one from there, or you can define your own face).
E.g. here's a snippet to use a predefined face:
(setq s (copy-sequence "sring"))
(put-text-property 0 6 'face 'custom-invalid s)
(setq mode-line-end-spaces s)
Answered by NickD on December 11, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP