Emacs font lock mode: provide a custom color instead of a face
Asked Answered
G

1

8

On this page discussing font lock mode, an example is provided which highlights a custom pattern:

 (add-hook 'c-mode-hook
           (lambda ()
            (font-lock-add-keywords nil
             '(("\\<\\(FIXME\\):" 1 font-lock-warning-face t)))))

Is there a way to provide a custom color instead of font-lock-warning-face and without defining a new custom face. I want to be able to write something like:

(font-lock-add-keywords nil '(("\\<\\(FIXME\\):" 1 "Blue" t)))

or an RGB color definition:

(font-lock-add-keywords nil '(("\\<\\(FIXME\\):" 1 "#F0F0F0" t)))

Using the double quotes doesn't work. Do you know what will make it work?

Garrot answered 6/6, 2011 at 21:51 Comment(0)
T
14
(font-lock-add-keywords nil '(("\\<\\(FIXME\\):" 1 '(:foreground "blue") t)))
(font-lock-add-keywords nil '(("\\<\\(FIXME\\):" 1 '(:foreground "#F0F0F0") t)))

A full list of attributes is in the manual.

Townshend answered 7/6, 2011 at 0:4 Comment(3)
Thank you for the clear concise answer, I should have known that.Garrot
nschum, how to add more properties to the face like making it bold? I tried something like: (font-lock-add-keywords nil '(("\\<\(FIXME\):" 1 '(:foreground "blue" :bold t) t))) But that did not work.Grantham
Your approach is correct, but :bold is not a valid text property. Try :weight and check the link for more details.Townshend

© 2022 - 2024 — McMap. All rights reserved.