help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: font-lock function matcher sample


From: Stefan Monnier
Subject: Re: font-lock function matcher sample
Date: Tue, 03 Aug 2004 18:39:41 GMT
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50

> > How about the code below instead:
> > (defun beatnik-=-matcher-p (limit score-match)
> >    "Tries to find a word whose scrable score matches score-match.
> > If such a word was found, t is returned."
> >    (let (found)
> >      (while (and (setq found (re-search-forward
> >                               beatnik-font-matcher-regexp limit t))
> >                  (/= (beatnik-last-word-score) score-match)))
> >      found))

> This is almost what I intended. This sets `found' to `t' even when the asked
> for scrabble score via (beatnik-last-word-score) isn't found.

Huh?  The while loop is only exited if found is nil or if
(beatnik-last-word-score) is equal to score-match, AFAICT.

I don't understand the problem you're referring to.

> But when I move the `and' into the `setq' it doesn't work, meaning that it
> locks itself fontifying.

> (defun beatnik-=-matcher-p (limit score-match)
>    "Tries to find a word whose scrable score matches score-match.
> If such a word was found, t is returned."
>    (let (found)
>      ;; doesn't work:
>      (while (and (setq found (re-search-forward
>                            beatnik-font-matcher-regexp limit t))
>                     (/= (beatnik-last-word-score) score-match)))
>      found))

This code seems to be exactly equl to the one above.

> Well, what I really missed was a sample function. I think the one you posted
> could well serve as a template.  The info page ((elisp)Search-based
> Fontification.) had the needed input and output for the defun, but the
> doc-string for `font-lock-defaults' had neither.  Maybe it could point to the
> info page?

I've changed the docstring to mention the fact that point is expected to
move, and to mention that it should all behave like re-search-forward.

> And the biggest nuisance in figuring this out was that emacs crashed a lot
> when getting things wrong in the defun.  It gave lots of `malloc' errors
> and `double free' errors.  Which is, of course, not a pretty way to cancel
> fontifying ;-) .

These bugs should be reported and fixed (but there's no point reporting them
unless you can provide a reliable recipe to reproduce them or unless you can
verify that they are still present in the CVS version of Emacs).

But even if they get fixed, I agree that debugging font-lock-keywords
settings is painful.  Turning off jit-lock-mode can help, tho.


        Stefan


reply via email to

[Prev in Thread] Current Thread [Next in Thread]