How to color @ (character) in Emacs?

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 colors all keywords starting with "bla". Example: blaTest123_test

However, when I try to add @ (the "at" character) instead of the "bla", it does not seem to work. I do not think that @ is a special character for regular expressions.

Do you know how I can get emacs to highlight keywords starting with an @?

+3
source share
1 answer

Your problem is in \<your regular expression, which

, . `\ & ;" ( ) , .

@ .

: M-: (info "(elisp) Regexp Backslash") RET

@:

(font-lock-add-keywords nil
  '(("@" 0 font-lock-warning-face t)))

- , , BOL .

(font-lock-add-keywords nil
  '(("\\(?:^\\|\\s-\\)\\(@[a-zA-Z1-9_]*\\)" 1 font-lock-warning-face t)))
+3

Source: https://habr.com/ru/post/1793768/


All Articles