I can color keywords in emacs using the following lisp code in .emacs:
(add-hook 'c-mode-common-hook
(lambda () (font-lock-add-keywords nil
'(("\\<\\(bla[a-zA-Z1-9_]*\\)" 1 font-lock-warning-face t)))))
This code color all keywords that start with “bla”. Example: blaTest123_test
However when I try to add @ (the ‘at’ symbol) instead of “bla”, it doesn’t seem to work. I don’t think @ is a special character for regular expressions.
Do you know how I can get emacs to highlight keywords starting with the @ symbol?
Your problem is the
\<in your regexp, whichand
@is not a word-constituent character.See: M-:
(info "(elisp) Regexp Backslash")RETThis unrestricted pattern will colour any
@:And this will do something like what you want, by requiring either BOL or some white space immediately beforehand.