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: Wed, 15 Jul 2009 16:51:11 -0700 (PDT) Organization: http://groups.google.com Message-ID: 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 1247720151 6686 80.91.229.12 (16 Jul 2009 04:55:51 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 16 Jul 2009 04:55:51 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jul 16 06:55:44 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 1MRJ0S-0000b5-6b for geh-help-gnu-emacs@m.gmane.org; Thu, 16 Jul 2009 06:55:44 +0200 Original-Received: from localhost ([127.0.0.1]:55202 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MRJ0R-0005fM-DI for geh-help-gnu-emacs@m.gmane.org; Thu, 16 Jul 2009 00:55:43 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!13g2000prl.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help,comp.emacs Original-Lines: 69 Original-NNTP-Posting-Host: 76.102.12.87 Original-X-Trace: posting.google.com 1247701871 17710 127.0.0.1 (15 Jul 2009 23:51:11 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Wed, 15 Jul 2009 23:51:11 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: 13g2000prl.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:170938 comp.emacs:98406 X-Mailman-Approved-At: Thu, 16 Jul 2009 00:50:24 -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:66132 On Jul 15, 4:37 am, gento wrote: > Hi All, > > I'm using emacs to edit journal text files *.jou, for which the > commented lines > starts with the character "/". > > I got two working solutions to have emacs recognize the "*.jou" files > and > apply the corresponding comment syntax automatically. > > Namely I add to the .emacs file either > > (require 'cl) > (push '("\\.jou$" . (lambda () (text-mode) (setf comment-start "/"))) > auto-mode-alist) > > or > > (add-hook 'find-file-hooks > (lambda () > (when (string-match "\\.jou$" (buffer-file-name)) > (setq comment-start "/") > ) > ) > ) > > For the moment I'm using the latter macro. > > Now I would also like to enable the syntax highlighting for comments. > > Does anybody know how I can modify one of the previous code snippets > in order to turn the text of the commented lines into red ? > > I appreciate any help. for syntax coloring comment, and if your comment syntax is simple as used in most popular langs, then, all you have to do is to setup emacs's syntax table for the comment chars, then syntax coloring will automatically work on comments. like this (code untested): (modify-syntax-entry ?/ "< b" jou-mode-syntax-table) (modify-syntax-entry ?\n "> b" jou-mode-syntax-table) for detail, see: =E2=80=A2 How To Add Comment Handling In Your Major Mode http://xahlee.org/emacs/elisp_comment_handling.html The best thing i think in your case, is just to create a mode for your .jou file. It's pretty easy. This tutorial may help: =E2=80=A2 How To Write A Emacs Major Mode For Syntax Coloring http://xahlee.org/emacs/elisp_syntax_coloring.html your code plus the syntax coloring and commenting command should be no more than 50 lines. Prob 20 will do. Once you have a mode, say jou- mode.el, than you can have this code associate the mode with .jou files: (add-to-list 'auto-mode-alist '("\\.jou\\'" . jou-mode)) try my tutorial and let me know if it solves your problem. Xah =E2=88=91 http://xahlee.org/ =E2=98=84