Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 389
Alan Turing Avatar asked Jun 06 '11 21:06

Alan Turing


People also ask

How do I customize my face in Emacs?

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.

What is Emacs font lock?

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.

How to turn off Font Lock?

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.


1 Answers

(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.

like image 159
nschum Avatar answered Nov 09 '22 14:11

nschum