From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Bruno Barbier Newsgroups: gmane.emacs.help Subject: Re: syntax highlighting for comments Date: 15 Sep 2009 19:03:10 GMT Organization: les newsgroups par Orange Message-ID: <4aafe4ee$0$12656$ba4acef3@news.orange.fr> References: <42fdb144-4df2-4489-9842-243504e404d0@a7g2000yqo.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1253076438 31653 80.91.229.12 (16 Sep 2009 04:47:18 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 16 Sep 2009 04:47:18 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Sep 16 06:47:11 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 1MnmQ9-0003wP-SI for geh-help-gnu-emacs@m.gmane.org; Wed, 16 Sep 2009 06:47:10 +0200 Original-Received: from localhost ([127.0.0.1]:48720 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MnmQ9-0007XG-34 for geh-help-gnu-emacs@m.gmane.org; Wed, 16 Sep 2009 00:47:09 -0400 Original-Path: news.stanford.edu!usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!proxad.net!feeder1-2.proxad.net!fdn.fr!news.wanadoo.fr!news.wanadoo.fr!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: slrn/0.9.9p1 (Linux) Original-Lines: 74 Original-NNTP-Posting-Date: 15 Sep 2009 21:03:10 CEST Original-NNTP-Posting-Host: 90.26.72.176 Original-X-Trace: 1253041390 news.orange.fr 12656 90.26.72.176:9092 Original-X-Complaints-To: abuse@orange.fr Original-Xref: news.stanford.edu gnu.emacs.help:173045 X-Mailman-Approved-At: Wed, 16 Sep 2009 00:41:26 -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:68178 Archived-At: On 2009-09-15, bj wrote: > any idea? > > On 8 Set, 10:26, gento wrote: >> Hi All, >> >> I'm using emacs to edit journal text files *.jou, for which commented >> lines >> start with the character "/". >> >> I apply the comment syntax for the "*.jou" files by adding to >> the .emacs file >> the lines >> >> (add-hook 'find-file-hooks >>  (lambda () >>   (when (string-match "\\.jou$" (buffer-file-name)) >>    (setq comment-start "/") >>   ) >>  ) >> ) >> >> Now I would also like to turn the text of the commented lines into >> red, and for this >> I added the line >> >> (font-lock-add-keywords nil '("\\(/.*\\)$" (1 font-lock-comment- >> face))) >> >> which unfortunately doesn’t work. >> >> Does anybody know where the mistake is? >> Many thanks >> >> gento > I don't have any major-mode for "*.jou" files; if you don't have either, the following should work for you. (add-hook 'find-file-hooks (lambda () (when (string-match "\\.jou$" (buffer-file-name)) ) (font-lock-add-keywords nil '("\\(/.*\\)$" (1 font-lock-comment-face))) (font-lock-mode) ) ) So, in short: 1) Your line with `font-lock-add-keywords' must be evaluated in the right buffer. 2) And you have to turn `font-lock-mode' on in the buffer for fontification to happen. If you want to add more features, you should probably take the time to define your own major mode "jou-mode": (info "(emacs)Major modes") (info "(elisp)Major modes") PS: I don't know what "jou" files are, but, if you are writing your own journal file, you should give `org-mode' a try; it's a wonderful addictive tool to take notes, to make plan and publish everything in LaTeX, HTML, etc. And it is included in recent versions of GNU Emacs. http://orgmode.org/