From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: font-lock function matcher sample Date: Tue, 03 Aug 2004 18:39:41 GMT Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1091558514 5409 80.91.224.253 (3 Aug 2004 18:41:54 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 3 Aug 2004 18:41:54 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Aug 03 20:41:42 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1Bs4EH-0006lO-00 for ; Tue, 03 Aug 2004 20:41:42 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1Bs4Hj-0007P0-QS for geh-help-gnu-emacs@m.gmane.org; Tue, 03 Aug 2004 14:45:15 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!logbridge.uoregon.edu!snoopy.risq.qc.ca!charlie.risq.qc.ca!53ab2750!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 56 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 Original-NNTP-Posting-Host: 132.204.24.84 Original-X-Complaints-To: abuse@umontreal.ca Original-X-Trace: charlie.risq.qc.ca 1091558381 132.204.24.84 (Tue, 03 Aug 2004 14:39:41 EDT) Original-NNTP-Posting-Date: Tue, 03 Aug 2004 14:39:41 EDT Original-Xref: shelby.stanford.edu gnu.emacs.help:124636 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:19969 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:19969 > > 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