From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "rgb" Newsgroups: gmane.emacs.help Subject: Re: How to implement comments that always start at the beginning of a line Date: 24 Oct 2006 08:07:07 -0700 Organization: http://groups.google.com Message-ID: <1161702427.798802.92160@k70g2000cwa.googlegroups.com> References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: sea.gmane.org 1161704469 1073 80.91.229.2 (24 Oct 2006 15:41:09 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 24 Oct 2006 15:41:09 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Oct 24 17:41:07 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1GcOOL-00072N-T4 for geh-help-gnu-emacs@m.gmane.org; Tue, 24 Oct 2006 17:40:38 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GcOOL-0004f6-8N for geh-help-gnu-emacs@m.gmane.org; Tue, 24 Oct 2006 11:40:37 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!k70g2000cwa.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 54 Original-NNTP-Posting-Host: 63.91.129.20 Original-X-Trace: posting.google.com 1161702433 26187 127.0.0.1 (24 Oct 2006 15:07:13 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Tue, 24 Oct 2006 15:07:13 +0000 (UTC) User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: k70g2000cwa.googlegroups.com; posting-host=63.91.129.20; posting-account=C7LM4w0AAAD23IRuMuUUJVCLQTuHhTK8 Original-Xref: shelby.stanford.edu gnu.emacs.help:142622 Original-To: help-gnu-emacs@gnu.org 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:38243 Archived-At: Philipp wrote: > Hi, > > I'm writing my own Emacs major mode for a language in with all comments > start with an starisk at the beginning of a line. Unfortunately, I haven't > found a way to implement this in the syntax table. > > I tried to do a two-character comment sequence, with the first character > being a newline and the 2nd character an asterisk. This would neglect > comments in the first line of a buffer, but it would be better than nothing. > The lines I used were > > (modify-syntax-entry ?\n ">1" form-mode-syntax-table) > (modify-syntax-entry ?* ".2" form-mode-syntax-table) > > but that didn't work the way I expected. Does anybody have an idea how to > solve this? You probably found that it only recognized every other comment line or something basically similar. It's because the newline character can't be both part of a comment starter and a comment ender at the same time. The only way to get exactly what you want is to use font-lock-syntactic-keywords to assign comment starter syntax specifically to to the characters you want. Modified version of code ripped from ddl-mode... (defvar ddl-font-lock-syntactic-keywords `(("^\\*" (0 "<"))) "A list of regexp's or functions. Used to add syntax-table properties to characters that can't be set by the syntax-table alone.") ... Later used in the "Further item elements" section of font-lock-defaults. ;; I use font-lock-syntactic-keywords to set some properties ;; and I don't want them ignored. (set (make-local-variable 'parse-sexp-lookup-properties) t) (set (make-local-variable 'font-lock-defaults) '(ddl-font-lock-keywords ;; keywords-only means no strings or comments get fontified nil ;; case-fold (ignore case) t ;; syntax-alist, nothing needs overriding nil ;; syntax-begin - move outside syntactic block nil ;; Further elements - set font-lock-syntactic-keywords (font-lock-syntactic-keywords . ddl-font-lock-syntactic-keywords)))