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?
Put the TextCursor (not the MousePointer) on text in that face and use the command 'M-x customize-face' – just hit 'RET' (Return) to accept the default face proposed; it is the face of the text under the cursor. Browse Customize and fish for the name of the face you want to customize.
Font Lock mode is a buffer-local minor mode that automatically attaches face properties to certain parts of the buffer based on their syntactic role. How it parses the buffer depends on the major mode; most major modes define syntactic criteria for which faces to use in which contexts.
Font Lock mode is enabled by default in major modes that support it. To toggle it in the current buffer, type M-x font-lock-mode . A positive numeric argument unconditionally enables Font Lock mode, and a negative or zero argument disables it.
(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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With