From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: highlighting large regions (comments) with font-lock keywords Date: Tue, 27 Sep 2011 21:30:43 -0400 Message-ID: References: <871uv17nar.fsf@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1317173453 18204 80.91.229.12 (28 Sep 2011 01:30:53 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 28 Sep 2011 01:30:53 +0000 (UTC) Cc: emacs-devel@gnu.org To: Eric Schulte Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Sep 28 03:30:49 2011 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1R8iz2-0007Vf-Sm for ged-emacs-devel@m.gmane.org; Wed, 28 Sep 2011 03:30:49 +0200 Original-Received: from localhost ([::1]:60780 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R8iz2-0003PI-Ap for ged-emacs-devel@m.gmane.org; Tue, 27 Sep 2011 21:30:48 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:40248) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R8iz0-0003PD-J4 for emacs-devel@gnu.org; Tue, 27 Sep 2011 21:30:47 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R8iyz-00089q-GI for emacs-devel@gnu.org; Tue, 27 Sep 2011 21:30:46 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.183]:32317 helo=ironport2-out.pppoe.ca) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R8iyz-00089j-CS for emacs-devel@gnu.org; Tue, 27 Sep 2011 21:30:45 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av0EAIZ3gk5FpZLc/2dsb2JhbABBqAJ5gVMBAQQBViMFCws0EhQYDSSIC7kVhwsEoF+EQw X-IronPort-AV: E=Sophos;i="4.68,452,1312171200"; d="scan'208";a="138850915" Original-Received: from 69-165-146-220.dsl.teksavvy.com (HELO ceviche.home) ([69.165.146.220]) by ironport2-out.pppoe.ca with ESMTP/TLS/ADH-AES256-SHA; 27 Sep 2011 21:30:43 -0400 Original-Received: by ceviche.home (Postfix, from userid 20848) id CCFF6660B6; Tue, 27 Sep 2011 21:30:43 -0400 (EDT) In-Reply-To: <871uv17nar.fsf@gmail.com> (Eric Schulte's message of "Tue, 27 Sep 2011 14:17:16 -0600") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.154.183 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:144427 Archived-At: > I'm working on a major mode for a new language [1] which comments > regions between \* ... *\. I've properly (I believe) instantiated > font-lock keywords, and I have added a function to the > `font-lock-extend-region-functions' list to ensure that both ends of a > comment are always considered at the same time but unfortunately comment > highlighting often does not work. > Specifically, when I first enter a buffer and right after calling > `shen-mode' all comments are properly highlighted, however as I edit and > navigate in the buffer larger comments often lose fontification. Let's see: (defun shen-font-lock-extend-region-comment () "Move fontification boundaries to contain whole comments." (let ((changed nil)) (goto-char font-lock-beg) (when (and (re-search-forward "\\\\\\*" font-lock-end t) (< (match-beginning 0) font-lock-beg)) (setq font-lock-beg (match-beginning 0) changed t) (when (and (re-search-forward "\\*\\\\" nil t) (> (match-end 0) font-lock-end)) (setq font-lock-end (match-end 0) changed t))) changed)) We have an obvious problem here: after (goto-char font-lock-beg) we're at font-lock-beg, and after (re-search-forward "\\\\\\*" font-lock-end t), we can only be further, so (match-beginning 0) will never be < font-lock-beg. BTW, why not simply do: (defvar shen-mode-syntax-table (let ((table (make-syntax-table))) (modify-syntax-entry ?- "w" table) (modify-syntax-entry ?\\ ". 14" table) (modify-syntax-entry ?* ". 23" table) (modify-syntax-entry ?? "w" table) (modify-syntax-entry ?< "w" table) (modify-syntax-entry ?> "w" table) table) "Syntax table to use in shen-mode.") Oh, and I haven't looked any other part of the code, but just happened to see: (add-to-list 'font-lock-extend-region-functions 'shen-font-lock-extend-region-comment t)) Where the `local' arg is nil whereas it should be t (maybe the t was meant for `local' rather than for `append'?). Stefan