我正在尝试从fundamental-mode写一个派生模式。假设我有这个正则表达式:
但是它不能处理字符串
A ((foo)bar)? B
,我该如何告诉emacs使用以下面字体?
font-lock-keyword-face
在A
上font-lock-warning-face
在foo
上(而不是bar
)font-lock-constant-face
在B
上
(defvar myregexp
"\\(A\\) \\(?:\\(foo\\)bar \\)?\\(B\\)")
(setq mylang-font-lock-keywords `(
(, myregex 1 font-lock-keyword-face)
(, myregex 2 font-lock-warning-face)
(, myregex 3 font-lock-constant-face)
))
但是它不能处理字符串
A B
(emacs报告缺少捕获)。
myregex
一次,这将使代码加速约 3 倍。但您需要再将关键字包装在一对括号中。 - Stefan