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?

Drew
  • 29,895
  • 7
  • 74
  • 104
Alan Turing
  • 12,223
  • 16
  • 74
  • 116

1 Answers1

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.

nschum
  • 15,322
  • 5
  • 58
  • 56
  • Thank you for the clear concise answer, I should have known that. – Alan Turing Jun 07 '11 at 01:57
  • 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. – SFbay007 Aug 28 '13 at 00:07
  • 1
    Your approach is correct, but :bold is not a valid text property. Try :weight and check the link for more details. – nschum Aug 28 '13 at 09:07