For instance, why does (insert #("abc" 0 3 (face (:foreground "red"))))
not insert red text?
1 Answer
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
.
-
1
-
(insert (propertize "abc" 'face '(:foreground "red")))
See alsoadd-text-properties
andput-text-property
as alternative methods to colorize text ...; and, this can also be done with overlays if so desired ...