unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* Font-lock should ignore missing submatches
@ 2008-02-03 20:30 Jorgen Schaefer
  2008-02-04  5:12 ` Chong Yidong
  0 siblings, 1 reply; 2+ messages in thread
From: Jorgen Schaefer @ 2008-02-03 20:30 UTC (permalink / raw)
  To: bug-gnu-emacs

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




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Font-lock should ignore missing submatches
  2008-02-03 20:30 Font-lock should ignore missing submatches Jorgen Schaefer
@ 2008-02-04  5:12 ` Chong Yidong
  0 siblings, 0 replies; 2+ messages in thread
From: Chong Yidong @ 2008-02-04  5:12 UTC (permalink / raw)
  To: bug-gnu-emacs

Jorgen Schaefer <forcer@forcix.cx> writes:

> When using font-lock-mode to highlight complex expressions, the
> font locking engine crashes when one of the subexpressions
> specified was not matched.

The engine doesn't "crash"; it signals an error, and Emacs continues
to function.  This is the intended behavior.

> Is there any chance to make font-lock just ignore unmatched
> subexpressions?

Yes.  See the LAXMATCH option in the node Customizing Keywords in the
Emacs Lisp Reference Manual.





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-02-04  5:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-03 20:30 Font-lock should ignore missing submatches Jorgen Schaefer
2008-02-04  5:12 ` Chong Yidong

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).