From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Xah Lee Newsgroups: gmane.emacs.help Subject: Re: How to enable the syntax highlighting for comments within files having a specific extension? Date: Thu, 16 Jul 2009 18:14:56 -0700 (PDT) Organization: http://groups.google.com Message-ID: <8acbfcb8-c833-465e-8708-407365784c6f@x6g2000prc.googlegroups.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1247805192 16025 80.91.229.12 (17 Jul 2009 04:33:12 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 17 Jul 2009 04:33:12 +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 Jul 17 06:33:05 2009 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 1MRf84-0000W6-17 for geh-help-gnu-emacs@m.gmane.org; Fri, 17 Jul 2009 06:33:04 +0200 Original-Received: from localhost ([127.0.0.1]:37245 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MRf83-0006hw-Eh for geh-help-gnu-emacs@m.gmane.org; Fri, 17 Jul 2009 00:33:03 -0400 Original-Path: news.stanford.edu!headwall.stanford.edu!newsfeed.news2me.com!nx02.iad01.newshosting.com!newshosting.com!69.16.185.16.MISMATCH!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!x6g2000prc.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help,comp.emacs Original-Lines: 79 Original-NNTP-Posting-Host: 76.102.12.87 Original-X-Trace: posting.google.com 1247793297 17964 127.0.0.1 (17 Jul 2009 01:14:57 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Fri, 17 Jul 2009 01:14:57 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: x6g2000prc.googlegroups.com; posting-host=76.102.12.87; posting-account=bRPKjQoAAACxZsR8_VPXCX27T2YcsyMA User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/530.5 (KHTML, like Gecko) Chrome/2.0.172.33 Safari/530.5, gzip(gfe), gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:170973 comp.emacs:98414 X-Mailman-Approved-At: Fri, 17 Jul 2009 00:29:36 -0400 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:66162 Archived-At: On Jul 16, 6:13 am, bj wrote: > Dear Xah, > > Thanks for your help. > > I have partly reached my goals. > > Here is the jou-mode.el file which I built on the basis of your > tutorials: > > <--8---><--8---><--8---><--8---><--8---><--8---><--8---><--8---><--8---><= --8---><--8---><--8---> > > ;; the command to comment/uncomment text > (defun jou-comment-dwim (arg) > "Comment or uncomment current line or region in a smart way. For > detail, see `comment-dwim'." > (interactive "*P") > (require 'newcomment) > (let ((deactivate-mark nil) (comment-start "/") (comment-end "")) > (comment-dwim arg))) > > (setq myKeywords > `( > ) > ) > > ;; define the major mode. > (define-derived-mode jou-mode fundamental-mode > "you are in jou-mode" > (setq font-lock-defaults '(myKeywords)) > > (setq comment-start "/") > > (define-key jou-mode-map [remap comment-dwim] 'jou-comment-dwim) > > (modify-syntax-entry ?/ "< b" jou-mode-syntax-table) > (modify-syntax-entry ?\n "> b" jou-mode-syntax-table) > ) > <--8---><--8---><--8---><--8---><--8---><--8---><--8---><--8---><--8--- > > ><--8---><--8---><--8---> > > The comment syntax highlighting works, but I still have few questions. > > 1) Is the line (setq comment-start "/") which I have added really > needed? you don't need it. > 2) I don't need the keywords, but if I remove the relevant entries in > the jou-mode.el file > (i.e. lines 9-12, 17), the commented lines are no longer in red. I'll have to take some time to know the tech details, but it's pretty safe to jsut let your code be. > 3) if the comment string "/" is in the middle of a line, like the > division sign in an expression, > then the characters to the right of it are turned into red. Do you > know how to avoid this? if you want everything between / and newline char to be treated as comment, than that is what your code has told emacs to do. If you want to introduce some special case, then in short your comment syntax is a complex one. As such, it cannot be implemented by using just syntax table. You'll have to use emacs general mechanism for syntax coloring. I'm not expert enough to give you solution off hand, and my experiences with emacs syntax coloring mechanism is that it's quite difficult and complex to learn. Maybe someone else here can help. Thanks & good luck. Xah =E2=88=91 http://xahlee.org/ =E2=98=84