From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: font-lock and multiline comments Date: Fri, 09 Feb 2007 15:28:29 -0500 Message-ID: References: <1171052093.030862.26790@v33g2000cwv.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1171053698 22312 80.91.229.12 (9 Feb 2007 20:41:38 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 9 Feb 2007 20:41:38 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Feb 09 21:41:30 2007 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 1HFcYj-00045W-QW for geh-help-gnu-emacs@m.gmane.org; Fri, 09 Feb 2007 21:41:30 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HFcYj-0006j0-Dv for geh-help-gnu-emacs@m.gmane.org; Fri, 09 Feb 2007 15:41:29 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.umontreal.ca!news.umontreal.ca.POSTED!not-for-mail Original-NNTP-Posting-Date: Fri, 09 Feb 2007 14:28:29 -0600 Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.93 (gnu/linux) Cancel-Lock: sha1:iIcOK6t74Ck1DtfRVjelEymD6sM= Original-Lines: 56 Original-NNTP-Posting-Host: 132.204.27.213 Original-X-Trace: sv3-qHYNPxtYudrrEE25CTuVdWYGkM3DOSsI/M50N+K9okggfVyx4wbSkGt2DGc7t3736yujqwBO5Oqe/HK!kdY3rFbqqnFH6G+CrfPelLPjlXfepHaaHdQqXIBIK6VxZoFs41+6ZsGaA66u1+pd2rxtLP/k8A8T!cAzcd+6HqUSeSzn1tw== Original-X-Complaints-To: abuse@umontreal.ca X-DMCA-Complaints-To: abuse@umontreal.ca X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Original-Xref: shelby.stanford.edu gnu.emacs.help:145436 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:41041 Archived-At: > I am writing a new major mode for an in-house programming language. > We'd like to have emacs do syntactic highlighting on the comments. The > language supports two kinds of comments: > // In-line C++ style comments > Comments > Multi-line comments flagged by Comments/EndComments > Here is another line > EndComments > The in-line style I was able to easily add with a syntax table > modification. The multi-line comments, however, I can't do because the > syntax tables only support comment syntax with 1 or 2 characters. > I then turned to font-lock mode. Adding the following font-lock > keyword didn't work if there were more than maybe 7 or 8 lines between > Comments and EndComments: > '("^[ \t]*Comments\\(.\\|\n\\)*EndComments" . font-lock-comment-face) > Apparently font-lock regions aren't designed to span multiple lines? > Can someone tell me how to get font-lock to recognize and properly > mark these multi-line comments? Use `font-lock-syntactic-keywords' along the lines of (defvar foo-font-lock-syntactic-keywords '(("^Comments\\(\n\\)" (1 "< b")) ("EndComments$" (0 (unless (eq (match-beginning 0) (point-min)) (put-text-property (1- (match-beginning 0)) (match-beginning 0) 'syntax-table (eval-when-compile (string-to-syntax "> b"))) (put-text-property (1- (match-beginning 0)) (match-end 0) 'font-lock-multiline t) nil))))) and then set font-lock-defaults to (foo-font-lock-keywords ...blablabla... (font-lock-syntactic-keywords . foo-font-lock-syntactic-keywords)) See the docstring of font-lock-defaults to see how many entries to place before the f-l-s-k one. Note that it will not work correctly for Comments EndComments :-( Stefan