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: Arjan Bos
Subject: Re: font-lock function matcher sample
Date: Sun, 25 Jul 2004 21:55:09 +0200
User-agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7) Gecko/20040616

Alan Mackenzie wrote:
Arjan Bos <Arjan.Bos@nospam.iseeyou.nl> wrote on Sat, 17 Jul 2004
23:08:59 +0200:

The font-lock function matcher wasn't (and possibly still isn't) fully
documented in the elisp manual.  The following may be helpful:

     When FUNCTION is called, it receives one argument, the limit of the
     search.  Its search should start at point and not extend beyond the
     limit.  FUNCTION should return non-`nil' if it succeeds, and set the
     match data to describe the match that was found.  FUNCTION will be
     called repeatedly with the same limit, and with point where the
     previous invocation left it, until it fails.  It need not reset
     point to a sensible value on failure.

Yeah, I found that passage. It was useful, up to a point. What I have now, works slightly better. I found out that I need to find words and calculate their scrabble-score. Is it true then that I need to keep on searching forward until I find a word whose scrabble score matches 6 (or until I reach limit)? If so, I'm having trouble when point is at (- limit 1). When that's the case, the matcher function is called repeatedly without stopping.


I'm looking for a way to fontify words accoriding to their scrabble
score. So if a word would score 6 points in american scrabble, it
should get a certain font-locking.


Currently, I have the following elisp, but it does not work.


Have you discovered the joys of edebug, yet?  If not, I thoroughly
recommend you to invest a few hours learning it.  For example, put point
inside `scrabble-6-matcher' and do C-u C-M-x to instrument it for edebug.
Normally I call M-x edebug-defun. How is this different?

Then call the function directly with M-: (scrabble-6-matcher 200).
Enjoy!

A hint: if you're going to be using edebug within "live" font-lock
routines, do this first:  M-: (setq font-lock-support-mode nil).
Otherwise the jit-lock timer routine will kick in 3 seconds after you've
starting looking at your function, destroying your concentration and
peace of mind.
I tried it without the (setq ...) It didn't destroy anything. In fact, it didn't do anything at all. Although, come to think of it, I got a few malloc error messages from emacs in my console. But maybe that is because I'm using a cvs emacs from a week ago.


As for locking the system, I suspect you've got into an infinite loop
with your regular expression: (re-search-forward "\\([a-z]\\)*" limit t).
This regexp will match any sequence of lower case letters, including an
empty one.  ;-(.  Probably you really want something more like
"\\([a-z]\\)+".  Then ask yourself whether you really want the "+"
_outside_ the grouping parentheses.  ;-)

Thanks, currently I'm having a bit more success with "\\<\\(.+?\\)\\>


Have fun!
Thanks! This /is/ fun! It's my summer holiday project. Done when I do not have to decorate my house (you know how spouses are ;-) )

Arjan

--
--
If you really want to contact me, then replace the "I see you" text by its three letter accronym, ICU.

Fabricate Diem PVNC, Motto of the Night Watch -- Terry Pratchett


reply via email to

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