From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Davis Herring Newsgroups: gmane.emacs.devel Subject: Re: Conditionalized font-locking? Date: Thu, 10 May 2012 09:30:17 -0600 Organization: XCP-1 Message-ID: <4FABDF09.7030704@lanl.gov> References: <871umw74yr.fsf@escher.home> <87ipg858fd.fsf@escher.home> <87ipg49i3l.fsf@escher.home> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1336663846 17328 80.91.229.3 (10 May 2012 15:30:46 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 10 May 2012 15:30:46 +0000 (UTC) Cc: Stefan Monnier , emacs-devel@gnu.org To: Stephen Berman Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu May 10 17:30:45 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 1SSVKG-0005gB-L7 for ged-emacs-devel@m.gmane.org; Thu, 10 May 2012 17:30:44 +0200 Original-Received: from localhost ([::1]:34049 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSVKF-0003Qn-SQ for ged-emacs-devel@m.gmane.org; Thu, 10 May 2012 11:30:43 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:48373) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSVK8-0003QZ-Kr for emacs-devel@gnu.org; Thu, 10 May 2012 11:30:42 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SSVK0-00056P-0P for emacs-devel@gnu.org; Thu, 10 May 2012 11:30:36 -0400 Original-Received: from proofpoint4.lanl.gov ([204.121.3.52]:39078) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSVJz-00055A-NX for emacs-devel@gnu.org; Thu, 10 May 2012 11:30:27 -0400 Original-Received: from mailrelay1.lanl.gov (mailrelay1.lanl.gov [128.165.4.101]) by proofpoint4.lanl.gov (8.14.4/8.14.4) with ESMTP id q4AFUIeO004021; Thu, 10 May 2012 09:30:18 -0600 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by mailrelay1.lanl.gov (Postfix) with ESMTP id 7F005E150F3; Thu, 10 May 2012 09:30:18 -0600 (MDT) X-NIE-2-Virus-Scanner: amavisd-new at mailrelay1.lanl.gov Original-Received: from [128.165.123.187] (xray-r07.lanl.gov [128.165.123.187]) by mailrelay1.lanl.gov (Postfix) with ESMTP id 6A101E150EE; Thu, 10 May 2012 09:30:18 -0600 (MDT) User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110717 Lanikai/3.1.11 In-Reply-To: <87ipg49i3l.fsf@escher.home> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.6.7580, 1.0.260, 0.0.0000 definitions=2012-05-10_05:2012-05-10, 2012-05-10, 1970-01-01 signatures=0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 204.121.3.52 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:150423 Archived-At: > (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. 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. Davis -- This product is sold by volume, not by mass. If it appears too dense or too sparse, it is because mass-energy conversion has occurred during shipping.