From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: gento Newsgroups: gmane.emacs.help Subject: Re: syntax highlighting for comments Date: Thu, 17 Sep 2009 03:29:14 -0700 (PDT) Organization: http://groups.google.com Message-ID: <9da5577a-80fb-4a5c-8fde-598ca8675b52@n2g2000vba.googlegroups.com> References: <42fdb144-4df2-4489-9842-243504e404d0@a7g2000yqo.googlegroups.com> <4aafe4ee$0$12656$ba4acef3@news.orange.fr> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1253184088 20075 80.91.229.12 (17 Sep 2009 10:41:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 17 Sep 2009 10:41:28 +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 Sep 17 12:41:21 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 1MoEQS-0004GX-Nd for geh-help-gnu-emacs@m.gmane.org; Thu, 17 Sep 2009 12:41:21 +0200 Original-Received: from localhost ([127.0.0.1]:54804 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MoEQR-0006WV-M9 for geh-help-gnu-emacs@m.gmane.org; Thu, 17 Sep 2009 06:41:19 -0400 Original-Path: news.stanford.edu!usenet.stanford.edu!postnews.google.com!n2g2000vba.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 97 Original-NNTP-Posting-Host: 80.75.192.71 Original-X-Trace: posting.google.com 1253183354 24848 127.0.0.1 (17 Sep 2009 10:29:14 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Thu, 17 Sep 2009 10:29:14 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: n2g2000vba.googlegroups.com; posting-host=80.75.192.71; posting-account=m5mUNAoAAACclRRo3KuF4zL6ydgW80wn User-Agent: G2/1.0 X-HTTP-Via: 1.0 chbad-s-sa2px02.ch.abb.com:8080 (squid/2.5.STABLE12) X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729),gzip(gfe),gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:173111 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:68233 Archived-At: Thank you very much Bruno! I'm using this (add-hook 'find-file-hooks (lambda () (when (string-match "\\.jou$" (buffer-file-name)) (setq comment-start "/") (font-lock-add-keywords nil '("\\(/.*\\)$" (1 font-lock-comment- face))) (font-lock-mode) ) ) ) and it works. Have a nice day Bruno Barbier wrote: > 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 > >> =A0(lambda () > >> =A0 (when (string-match "\\.jou$" (buffer-file-name)) > >> =A0 =A0(setq comment-start "/") > >> =A0 ) > >> =A0) > >> ) > >> > >> 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=92t 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/