From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eric Newsgroups: gmane.emacs.help Subject: Multiline Font Lock Date: Wed, 10 Sep 2008 07:50:34 -0700 (PDT) Organization: http://groups.google.com Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1221061847 11151 80.91.229.12 (10 Sep 2008 15:50:47 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 10 Sep 2008 15:50:47 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Sep 10 17:51:40 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KdRyF-0006wM-4R for geh-help-gnu-emacs@m.gmane.org; Wed, 10 Sep 2008 17:51:07 +0200 Original-Received: from localhost ([127.0.0.1]:52328 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KdRxF-0004DT-0C for geh-help-gnu-emacs@m.gmane.org; Wed, 10 Sep 2008 11:50:05 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!k7g2000hsd.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 70 Original-NNTP-Posting-Host: 129.42.161.36 Original-X-Trace: posting.google.com 1221058234 15002 127.0.0.1 (10 Sep 2008 14:50:34 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Wed, 10 Sep 2008 14:50:34 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: k7g2000hsd.googlegroups.com; posting-host=129.42.161.36; posting-account=baqlugoAAADGe3uZxwXNJvS9trKLtCm1 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.29 Safari/525.13, gzip(gfe), gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:162047 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: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:57390 Archived-At: I'm trying to set up multiline font-locking for a major mode I've been working on. I've spent a fair bit of time wrestling with it, but I'm still not getting completely desired results. Emacs correctly fontifies the multiline region, and then correctly refontifies it when the fontify-region function gets called again. The problem is that when I make changes in the middle of the region, the modified line and subsequent line get defontified until Emacs comes through and refontifies. When I set font-lock-multiline variable to 't', the text is never defontified and new text is always immediately fontified correctly (and without the aid of my region function [see below]). I'm guessing then that there's some problem with my regexp or with the way I'm applying my font-lock-multiline property. What should I be doing differently so that I get the same behavior without needing to turn font-lock-multiline on? Do I just _need_ to set the font-lock-multiline variable to get the desired behavior? The syntax for one of these multiline groups is: JAVA_ON whatever text your heart desires with any {{punctuation}}} until JAVA_OFF ------ The emacs function I've added to font-lock-extend-region-functions is below: (defun ecf-font-lock-multiline-java-block-check () "Ensures that no java block exists in the region or that a full java block exists in the region. Returns t if the region had to be changed or nil if no changes were needed." ;;There seems to be no way around the warning about font-lock-beg and font-lock-end without binding them ourselves with defvar. We need to use them (and they're defined for us in the function that will call this one). (let ((changed)) (save-excursion (when (> font-lock-beg (point-min)) ;look for a JAVA_OFF with no matching JAVA_ON (goto-char font-lock-beg) (when (re-search-forward "JAVA_OFF" font-lock-end t) (when (> font-lock-beg (re-search-backward "JAVA_ON" (point-min) t)) ;moves point to JAVA_ON or begin of buffer (setq font-lock-beg (point)) (setq changed t)))) (when (< font-lock-end (point-max)) ;look for a JAVA_ON with no matching JAVA_OFF (goto-char font-lock-end) (if (re-search-backward "JAVA_ON" font-lock-beg t) (when (< font-lock-end (re-search-forward "JAVA_OFF" (point-max) t)) (end-of-line) (setq font-lock-end (point)) (setq changed t)))) (goto-char font-lock-beg) (while (re-search-forward "JAVA_ON" font-lock-end t) (let ((start-java-block (- (point) 7)) (end-java-block (+ 1 (re-search-forward "JAVA_OFF" font-lock- end)))) (put-text-property start-java-block end-java-block font-lock- multiline t) ))) changed))