From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.devel Subject: Re: Conditionalized font-locking? Date: Thu, 10 May 2012 20:18:50 +0200 Message-ID: <87ehqraohh.fsf@escher.home> References: <871umw74yr.fsf@escher.home> <87ipg858fd.fsf@escher.home> <87ipg49i3l.fsf@escher.home> <4FABDF09.7030704@lanl.gov> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1336673949 5780 80.91.229.3 (10 May 2012 18:19:09 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 10 May 2012 18:19:09 +0000 (UTC) Cc: Stefan Monnier , emacs-devel@gnu.org To: Davis Herring Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu May 10 20:19:06 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SSXxC-0001UT-32 for ged-emacs-devel@m.gmane.org; Thu, 10 May 2012 20:19:06 +0200 Original-Received: from localhost ([::1]:49233 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSXxB-0005Vw-DS for ged-emacs-devel@m.gmane.org; Thu, 10 May 2012 14:19:05 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:48040) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSXx3-0005Vd-LS for emacs-devel@gnu.org; Thu, 10 May 2012 14:19:03 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SSXx1-0006HT-Lp for emacs-devel@gnu.org; Thu, 10 May 2012 14:18:57 -0400 Original-Received: from mailout-de.gmx.net ([213.165.64.22]:51832) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1SSXx1-0006Gm-CJ for emacs-devel@gnu.org; Thu, 10 May 2012 14:18:55 -0400 Original-Received: (qmail invoked by alias); 10 May 2012 18:18:52 -0000 Original-Received: from i59F57B4B.versanet.de (EHLO escher.home) [89.245.123.75] by mail.gmx.net (mp032) with SMTP; 10 May 2012 20:18:52 +0200 X-Authenticated: #20778731 X-Provags-ID: V01U2FsdGVkX1/Pylco25jPgjKT0LVDn2Q3T1uItBZZF6OscL/X3i e5uUq7NgLtLRal In-Reply-To: <4FABDF09.7030704@lanl.gov> (Davis Herring's message of "Thu, 10 May 2012 09:30:17 -0600") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux) X-Y-GMX-Trusted: 0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 213.165.64.22 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:150426 Archived-At: On Thu, 10 May 2012 09:30:17 -0600 Davis Herring wrote: >> (defun srb-date-time-matcher (lim) >> "Search for date-time strings within LIM for font-locking." >> (when (re-search-forward (concat "^\\(?1:[0-9][0-9][0-9][0-9]-" >> "[0-9][0-9]-[0-9][0-9]\\)" >> " \\(?2:[0-9]?[0-9]:[0-9][0-9]\\)?") >> lim t) >> (let* ((date (match-string-no-properties 1)) >> (time (match-string-no-properties 2)) >> ;; days-between needs a non-empty time string. >> (date-time (concat date " " (or time "00:00")))) >> (when (< (days-between date-time (current-time-string)) 0) >> (concat date " " time))))) >> [...] >> Fontification will call FUNCTION repeatedly with the same limit, >> and with point where the previous invocation left it, until >> FUNCTION fails. On failure, FUNCTION need not reset point in any >> particular way. > > If any of your searches turns up a date you don't like, your function > fails (returns nil), so font-lock gives up. You need to (unfortunately) > write much the same loop that font-lock is wrapping around your function > so that it finds the first date that it cares about rather than > returning nil. Thank you, that was the part I didn't quite understand. > The easy way to do this if you don't have too many dates being fontified > at one go is just to recursively call yourself when you don't like your > current match: > > (or (< ...) (srb-date-time-matcher lim)) > > Note that you needn't return any particular non-nil value on success; > it's the match-data that font-lock uses. This works perfectly, thanks very much! Steve Berman