[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Font-lock should ignore missing submatches
From: |
Jorgen Schaefer |
Subject: |
Font-lock should ignore missing submatches |
Date: |
Sun, 3 Feb 2008 20:30:56 +0000 (UTC) |
Hello!
When using font-lock-mode to highlight complex expressions, the
font locking engine crashes when one of the subexpressions
specified was not matched.
Consider:
(set (make-local-variable 'font-lock-keywords)
'(("\\(?:\\(foo\\) *\\)?\\(bar\\)"
(1 font-lock-comment-face)
(2 font-lock-string-face))))
I.e. "possibly match the foo that is followed by whitespace, then
definitively match a bar."
This will (correctly) highlight these expressions:
foobar
foo bar
etc.
But font-lock will error out if the first subexpression does not
match anything, even though the regular expression matches:
oobar
oo bar
bar
etc.
The code will give an appropriate error:
Error during redisplay: (error No match 1 in highlight (1
font-lock-comment-face))
Is there any chance to make font-lock just ignore unmatched
subexpressions?
Tested in:
- GNU Emacs 22.1.1
- GNU Emacs from CVS, approx. two weeks old
Sorry, no current CVS version here :-(
Regards,
-- Jorgen
- Font-lock should ignore missing submatches,
Jorgen Schaefer <=