help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: syntax highlighting for comments


From: Bruno Barbier
Subject: Re: syntax highlighting for comments
Date: 15 Sep 2009 19:03:10 GMT
User-agent: slrn/0.9.9p1 (Linux)

On 2009-09-15, bj <gento_distefano@hotmail.com> wrote:
> any idea?
>
> On 8 Set, 10:26, gento <gento_distef...@hotmail.com> 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/


reply via email to

[Prev in Thread] Current Thread [Next in Thread]