When setting up font-lock-keywords for a GNU/Emacs mode, is it possible to highlight multiple sub-expressions of a regular expression with a single matcher? What I’d like to do is something along the lines of:
("\\(foo\\)-\\(bar\\)" '(1 foo-face) '(2 bar-face))
What would be the correct syntax for something like that – or do I have to split it up into two distinct matchers?
Try something like this:
(i.e. the same as yours but without the extra quotes).
I say this because I have various bits like this in my custom font-lock-keywords definitions. Some of them have
nil ton the end of the second one, like this:which correspond to the
OVERRIDEandLAXMATCHoptional flags and may be necessary depending on your precise circumstances.The documentation for
font-lock-keywordsdiscusses this in some depth, although it’s not always the simplest to follow — I find it easier just to copy someone else’s working setup, like the existing value ofc-font-lock-keywords-3, for example.