1

我在 Emacs 中定义了一个新面孔,但是着色没有生效。以下是 中的面和模式定义~/.emacs

(defface sml-highlight-operator-face
  '((t (:foreground "red")))
  "SML operator highlighting"
  :group 'basic-faces)

(defvar sml-font-lock-keywords
   ((,(regexp-opt '("fun" "fn" "let" "val" "datatype" "type" "case" "of" "end" "structure" "struct" "signature" "sig"))
     (0 font-lock-keyword-face))
    ("[][=|><-+;,{}():]" (0 sml-highlight-operator-face))))

;;;###autoload
(define-derived-mode sml-mode prog-mode "SML"
  "SML major mode."
  (set (make-local-variable 'comment-start) "(* ")
  (set (make-local-variable 'comment-end) " *)")
  (set (make-local-variable 'font-lock-defaults)
       '(sml-font-lock-keywords)))

但是,当我使用font-lock-builtin-face而不是sml-highlight-operator-face突出显示这些字符时(尽管使用了我不想要的颜色)。我做错了什么?

4

1 回答 1

4

您的 font-lock-keywords 中的元素(0 sml-highlight-operator-face)不是说“使用 face sml-highlight-operator-face for sub-match 0”,而是“使用评估表达式的结果sml-highlight-operator-face作为要放在子匹配 0 上的面”。

IOW,您需要使用(0 'sml-highlight-operator-face).

顺便说一句,现在的惯例是不要-face为面使用后缀(当然,这样的后缀仍然用于保存面的变量),尽管我们还没有费心将font-lock-foo-face面重命名为font-lock-foo(尽管它会非常有助于您会看到很多字体锁定规则在哪里说的混乱(0 font-lock-foo-face),人们认为它指的是人font-lock-foo-face脸,而它指的是font-lock-foo-face变量(其值包含font-lock-foo-face人脸)。

于 2016-02-25T18:41:03.050 回答