2

我试图让 emacs 为 C 中的一些其他关键字着色。特别是,我添加了 RESTRICT。我做了:

(add-hook 'c-mode-common-hook
      (lambda ()
        (font-lock-add-keywords nil
                    '(("\\<\\(RESTRICT\\)\\>" . font-lock-keyword-face))) ))

但是,这(不出所料)只会导致 emacs 使用关键字面孔为“RESTRICT”实例着色。

“restrict”(小写)已经是 emacs 了解 C 关键字的一部分。所以,如果我声明:

int * restrict foo;

“int”用 type-face 着色,“restrict”用关键字 face 着色,“foo”用 variable-name-face 着色。但是用我的新 RESTRICT 词,如果我声明:

int * RESTRICT bar;

"int" 像以前一样着色,而 RESTRICT 用关键字面着色。但是“bar”对它没有影响。如果没有我的规则,“RESTRICT”将被着色为变量名面,而“bar”将不会被修改,这是正确的。

无论如何,问题是:如何使用变量名称面在第二个代码块中制作 emacs 颜色“条”?我希望emacs实际上将“RESTRICT”视为语言中的关键字(以便变量名被着色),而不仅仅是以某种方式为“RESTRICT”的实例着色。

4

1 回答 1

0

我的猜测是你想在 cc-langs.el (cc-mode的一部分)中覆盖这个定义:

(c-lang-defconst c-type-modifier-kwds
  "Type modifier keywords.  These can occur almost anywhere in types
but they don't build a type of themselves.  Unlike the keywords on
`c-primitive-type-kwds', they are fontified with the keyword face and
not the type face."
  t    nil
  c    '("const" "restrict" "volatile")
  c++  '("const" "volatile" "throw")
  objc '("const" "volatile"))

但是,我不是 cc 模式的专家,但我找不到明显的方法来覆盖此绑定。

于 2011-11-02T16:03:57.303 回答