From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: martin rudalics Newsgroups: gmane.emacs.devel Subject: Re: diary font-lock issue Date: Tue, 16 May 2006 23:42:49 +0200 Message-ID: <446A4759.6070209@gmx.at> References: <8jwtcmqvqm.fsf@fencepost.gnu.org> <4469F4AE.8030909@gmx.at> <1hac9hn99k.fsf@fencepost.gnu.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1147815982 32059 80.91.229.2 (16 May 2006 21:46:22 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 16 May 2006 21:46:22 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue May 16 23:46:14 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Fg7Me-0008KD-NE for ged-emacs-devel@m.gmane.org; Tue, 16 May 2006 23:46:02 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Fg7Me-0002yZ-3u for ged-emacs-devel@m.gmane.org; Tue, 16 May 2006 17:46:00 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Fg7MQ-0002yF-2p for emacs-devel@gnu.org; Tue, 16 May 2006 17:45:46 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Fg7MO-0002x6-KF for emacs-devel@gnu.org; Tue, 16 May 2006 17:45:45 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Fg7MO-0002wu-ID for emacs-devel@gnu.org; Tue, 16 May 2006 17:45:44 -0400 Original-Received: from [213.165.64.20] (helo=mail.gmx.net) by monty-python.gnu.org with smtp (Exim 4.52) id 1Fg7P7-0006Wi-3k for emacs-devel@gnu.org; Tue, 16 May 2006 17:48:33 -0400 Original-Received: (qmail invoked by alias); 16 May 2006 21:45:42 -0000 Original-Received: from N743P011.adsl.highway.telekom.at (EHLO [62.47.36.203]) [62.47.36.203] by mail.gmx.net (mp032) with SMTP; 16 May 2006 23:45:42 +0200 X-Authenticated: #14592706 User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: de-DE, de, en-us, en Original-To: Glenn Morris In-Reply-To: <1hac9hn99k.fsf@fencepost.gnu.org> X-Y-GMX-Trusted: 0 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:54609 Archived-At: >>`foo-font-lock-keywords' will fail to find a match when the end of >>`font-lock-fontify-region' is positioned as indicated above. [...] > > Just looking at this quickly, it looks to be doing the same job as the > regexp I originally quoted, but using a function instead to do the > match. Setting font-lock-multiline to t in the buffer means that it > gets added as a property to all fontified regions, so yours is more > elegant (only adding the property where needed), but the two ought to > be equivalent, right? Not really, I put a question mark at the end of the regexp. Hence I also match date lines not followed by a =[=]* line. To handle that very case - which is the cause of your problem - I use a function. You probably could do that more elegantly with anchored matches. > This all seems very complex. According to: > > > > "the font-lock-multiline property should be enough in all cases to > make it unnecessary to use an after-change-function hook." Indeed, it *should*, eventually ... > That's a long thread, but AFAICS, it seems that for simple keyword > fontification, setting font-lock-multiline for the buffer ought to be > enough. > > (Though later on I find: > > > > > (i) The matching of keywords which span line breaks; > ... setting the font-lock-multiline variable... won't reliably > take care of (i) > > which confuses me.) You might have to solve the following problem: Suppose you have the single line Friday, May 5, 2006 in your buffer and you type a "=" on the next line as in Friday, May 5, 2006 = There's no multiline property around before you type the "=" but you probably want to highlight the date line after. That's what my ugly after-change-hook is for. > I'm also confused as to why the initial fontification is not working > as it should. There are no "changes" involved in this instance. > (Indeed, the fancy diary buffer is not something one edits, so this is > about as simple as multiline font-lockign can get.) I explained that at the very beginning of this message. If you never edit the buffer you obviously don't need font-lock-multiline and you don't need the after-change hook either, just use a simplified version of foo-bar like (defun foo-bar (bound) (and (re-search-forward "\\(\\(?:\\(?:Fri\\|Mon\\|S\\(?:atur\\|un\\)\\|\\(?:T\\(?:hur\\|ue\\)\\|Wedne\\)s\\)day\\)\ , \\(?:A\\(?:pril\\|ugust\\)\\|December\\|February\\|J\\(?:anuary\\|u\\(?:ly\\|ne\\)\\)\ \\|Ma\\(?:rch\\|y\\)\\|\\(?:Novem\\|Octo\\|Septem\\)ber\\) [0-9]+, -?[0-9]+\n\\)\\(=+\n\\)?" bound t) (or (> (match-end 0) (match-end 1)) (and (= (match-end 1) bound) (save-match-data (looking-at "=+\n")))))) But never try to match things that span two or more lines the way you did. It will always fail at boundaries of jit-lock chunks.