Let's say I have a language which looks like this:
anchor (item something item some thing item some item thing) item item
and that I'm playing with font-lock a bit. I would like to highlight "anchor" as being a function and every "item" in the parens as well.
I tried the following:
(setq test-font-lock-keywords `( ("\\<anchor\\>" (0 font-lock-function-name-face) ("\\<item\\>" nil nil (0 font-lock-constant-face)) ) ) ) (define-derived-mode test-mode fundamental-mode "test mode" "Test mode" (kill-all-local-variables) (interactive) (setq font-lock-defaults '(test-font-lock-keywords)) )
My problem is that it considers every "item" word that comes after an "anchor" until the end of the line. The words "item item" in the end of my example should thus not receive syntax highlighting. There may be a way to achieve this with a post-form but I'm not sure that's how it's meant to be used or how to do it anyway.
So I tried with the following, much less sexy regular expression:
(setq regexp "\\(\\<anchor\\>\\)[\t ]*(\\(?:\\(item\\)\\|[^)]\\)*)") (setq test-font-lock-keywords `( (,regexp (1 font-lock-function-name-face) (2 font-lock-constant-face)) ) )
And it only highlights the last found "item" before the parens. How can I make this regex capture every "item" here represented with index 2?