I want to highlight foo
in foo::
without highlighting foo::<bar>
, using font-lock-keywords
. This is the result I want:
Initially I tried this:
(defvar example-font-lock-keywords
`((,(rx (group (1+ word)) "::" (not (any "<"))) 1 font-lock-type-face)))
(define-derived-mode example-mode prog-mode "Example"
(setq-local font-lock-defaults '(example-font-lock-keywords)))
But that gave the following:
Instead I tried two separate keywords:
(defvar example-font-lock-keywords
`((,(rx (group (1+ word)) "::") 1 font-lock-type-face)
;; This is ignored if I use `default', but other faces work!
(,(rx (group (1+ word)) "::<") 1 font-lock-variable-name-face t)))
(define-derived-mode example-mode prog-mode "Example"
(setq-local font-lock-defaults '(example-font-lock-keywords)))
The second pattern is used if I specify font-lock-variable-name-face
, but if I use default
, the whole pattern is ignored!