When I try to execute the following, font-lock fails abruptly after it matches the first group. A little bit of debugging with the neat tool font-lock-studio
and I realized that font-lock
is upset that it can't find group 2
. How can I tell it not to freak out?
(define-derived-mode expl3-mode prog-mode
"expl3"
"Mode for editing expl3 source code."
(setq font-lock-set-defaults nil)
(font-lock-set-defaults)
(font-lock-add-keywords
nil
`((,(rx (* whitespace)
(group (+ (any alnum "-")))
(* whitespace)
(optional "/" (* whitespace)
(group (+ (any alnum "_")))) ; note
(+ whitespace)
(group "." (+ (any alpha)) (optional "_"))
(group (optional (any alpha) (+ (any alpha "_"))))
(group ":" (* (any "nNpTFwcVvxofD"))))
(1 font-lock-variable-name-face t)
(2 font-lock-variable-name-face t) ; the optional group
(3 font-lock-type-face t)
(4 font-lock-function-name-face t)
(5 font-lock-keyword-face t)))))
Test string
test-key .tl_set:N ...
with / grouping .code:n ...
(optional "/" (* whitespace) (group (+ (any alnum "_"))))
. – Lindydancer Apr 5 '15 at 18:36