[英]How to color @ (at symbol) in Emacs?
I can color keywords in emacs using the following lisp code in .emacs: 我可以使用.emacs中的以下lisp代码在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". 此代码将所有以“bla”开头的关键字着色。 Example: blaTest123_test
示例:blaTest123_test
However when I try to add @ (the 'at' symbol) instead of "bla", it doesn't seem to work. 但是,当我尝试添加@('at'符号)而不是“bla”时,它似乎不起作用。 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? 你知道如何让emacs突出显示以@符号开头的关键字吗?
Your problem is the \\<
in your regexp, which 你的问题是你的正则表达式中的
\\<
matches the empty string, but only at the beginning of a word.
匹配空字符串,但仅限于单词的开头。 `\\<' matches at the beginning of the buffer (or string) only if a word-constituent character follows.
只有当后面有一个字组成字符时,`\\ <'才会匹配缓冲区(或字符串)的开头。
and @
is not a word-constituent character. 和
@
不是一个单词构成字符。
See: M-: (info "(elisp) Regexp Backslash")
RET 请参阅: M- :(
(info "(elisp) Regexp Backslash")
RET
This unrestricted pattern will colour any @
: 这种不受限制的模式将为任何
@
颜色着色:
(font-lock-add-keywords nil
'(("@" 0 font-lock-warning-face t)))
And this will do something like what you want, by requiring either BOL or some white space immediately beforehand. 通过事先要求BOL或一些空白区域,这将做你想要的事情。
(font-lock-add-keywords nil
'(("\\(?:^\\|\\s-\\)\\(@[a-zA-Z1-9_]*\\)" 1 font-lock-warning-face t)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.