For instance, why does (insert #("abc" 0 3 (face (:foreground "red")))) not insert red text?
Asked
Active
Viewed 135 times
5
extremeaxe5
- 659
- 3
- 11
1 Answers
7
You probably try that in the *scratch* buffer or any other buffer with active font-lock-mode.
In such a buffer the faces are immediately adapted to the rules prescribed by the variable font-lock-keywords.
Use the property font-lock-face instead of face in those buffers.
The modified version of your example would be:
(insert #("abc" 0 3 (font-lock-face (:foreground "red"))))
font-lock-face properties are directly translated into face properties by font-lock-mode. No fontification rules are applied to those stretches of text.
Side-note: lisp-interaction-mode is derived from emacs-lisp-mode that activates font-lock-mode.
Tobias
- 33,167
- 1
- 37
- 77
(insert (propertize "abc" 'face '(:foreground "red")))See alsoadd-text-propertiesandput-text-propertyas alternative methods to colorize text ...; and, this can also be done with overlays if so desired ... – lawlist Mar 18 '20 at 19:05