unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* syntax highlighting for comments
@ 2009-09-08  8:26 gento
  2009-09-15 16:49 ` bj
  0 siblings, 1 reply; 4+ messages in thread
From: gento @ 2009-09-08  8:26 UTC (permalink / raw)
  To: help-gnu-emacs

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: syntax highlighting for comments
  2009-09-08  8:26 syntax highlighting for comments gento
@ 2009-09-15 16:49 ` bj
  2009-09-15 19:03   ` Bruno Barbier
  0 siblings, 1 reply; 4+ messages in thread
From: bj @ 2009-09-15 16:49 UTC (permalink / raw)
  To: help-gnu-emacs

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



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: syntax highlighting for comments
  2009-09-15 16:49 ` bj
@ 2009-09-15 19:03   ` Bruno Barbier
  2009-09-17 10:29     ` gento
  0 siblings, 1 reply; 4+ messages in thread
From: Bruno Barbier @ 2009-09-15 19:03 UTC (permalink / raw)
  To: help-gnu-emacs

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/


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: syntax highlighting for comments
  2009-09-15 19:03   ` Bruno Barbier
@ 2009-09-17 10:29     ` gento
  0 siblings, 0 replies; 4+ messages in thread
From: gento @ 2009-09-17 10:29 UTC (permalink / raw)
  To: help-gnu-emacs

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 <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/


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-09-17 10:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-08  8:26 syntax highlighting for comments gento
2009-09-15 16:49 ` bj
2009-09-15 19:03   ` Bruno Barbier
2009-09-17 10:29     ` gento

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).