I was trying to get emacs to color some additional keywords in C. In particular, I to add RESTRICT. I did:
(add-hook 'c-mode-common-hook
(lambda ()
(font-lock-add-keywords nil
'(("\\<\\(RESTRICT\\)\\>" . font-lock-keyword-face))) ))
However, this (unsurprisingly) just causes emacs to color instances of "RESTRICT" with keyword-face.
"restrict" (lower case) is already part of emacs' knowledge of C keywords. So if I declare:
int * restrict foo;
The "int" is colored with type-face, "restrict" is colored with keyword-face, and "foo" is colored with variable-name-face. But with my new RESTRICT word, if I declare:
int * RESTRICT bar;
"int" is colored as before, and RESTRICT is colored with keyword-face. But "bar" has no effects on it. Without my rule in place, "RESTRICT" would be colored variable-name-face, and "bar" would be unmodified, which is proper.
Anyway, the question is: how can I make emacs color "bar" in the second code-block with variable-name-face? I want emacs to actually treat "RESTRICT" as a keyword in the language (so that variable names get colored), not just color instances of "RESTRICT" a certain way.
my guess is that you somehow want to override this definition in cc-langs.el (part of cc-mode):
however, i'm no expert in cc-mode but i couldn't find an obvious way to override this binding.