如何在 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)))))
此代码为所有以“bla”开头的关键字着色。示例:blaTest123_test
但是,当我尝试添加@(“at”符号)而不是“bla”时,它似乎不起作用。我不认为@是正则表达式的特殊字符。
你知道如何让 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 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题是正则表达式中的
\<
,并且
@
不是单词组成字符。请参阅: M-:
(info "(elisp) Regexp Backslash")
RET这种不受限制的模式将为任何
@
:这将通过预先要求 BOL 或一些空白来完成您想要的事情。
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.