使用 font-lock-add-keywords 定义新关键字会破坏/覆盖变量名称着色 (emacs)
我试图让 emacs 为 C 中的一些附加关键字着色。特别是,我添加了 RESTRICT。我做到了:
(add-hook 'c-mode-common-hook
(lambda ()
(font-lock-add-keywords nil
'(("\\<\\(RESTRICT\\)\\>" . font-lock-keyword-face))) ))
然而,这(不出所料)只会导致 emacs 使用关键字-face 对“RESTRICT”实例进行着色。
“restrict”(小写)已经是 emacs C 关键字知识的一部分。因此,如果我声明:
int * restrict foo;
“int”用 type-face 着色,“restrict”用 keywords-face 着色,“foo”用变量名-face 着色。但是对于我的新 RESTRICT 词,如果我声明:
int * RESTRICT bar;
“int”的颜色与以前一样,并且 RESTRICT 使用关键字面的颜色。但“bar”对其没有任何影响。如果没有我的规则,“RESTRICT”将是彩色的变量名称面,而“bar”将是未修改的,这是正确的。
不管怎样,问题是:如何在带有变量名面的第二个代码块中制作 emacs 颜色“条”?我希望 emacs 实际上将“RESTRICT”视为语言中的关键字(以便变量名称着色),而不仅仅是以某种方式对“RESTRICT”实例进行颜色处理。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的猜测是,您以某种方式想要在 cc-langs.el (cc-mode 的一部分)中覆盖此定义:
但是,我不是 cc-mode 方面的专家,但我找不到覆盖此绑定的明显方法。
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.