5

For instance, why does (insert #("abc" 0 3 (face (:foreground "red")))) not insert red text?

extremeaxe5
  • 659
  • 3
  • 11
  • I'll let another forum participant explain the "why" ... But, how about using?: (insert (propertize "abc" 'face '(:foreground "red"))) See also add-text-properties and put-text-property as alternative methods to colorize text ...; and, this can also be done with overlays if so desired ... – lawlist Mar 18 '20 at 19:05

1 Answers1

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