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

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

Re: How to enable the syntax highlighting for comments within files havi


From: Xah Lee
Subject: Re: How to enable the syntax highlighting for comments within files having a specific extension?
Date: Thu, 16 Jul 2009 18:14:56 -0700 (PDT)
User-agent: G2/1.0

On Jul 16, 6:13 am, bj <gento_distef...@hotmail.com> wrote:
> Dear Xah,
>
> Thanks for your help.
>
> I have partly reached my goals.
>
> Here is the jou-mode.el file which I built on the basis of your
> tutorials:
>
> <--8---><--8---><--8---><--8---><--8---><--8---><--8---><--8---><--8---><--8---><--8---><--8--->
>
> ;; the command to comment/uncomment text
> (defun jou-comment-dwim (arg)
>    "Comment or uncomment current line or region in a smart way. For
> detail, see `comment-dwim'."
>    (interactive "*P")
>    (require 'newcomment)
>    (let ((deactivate-mark nil) (comment-start "/") (comment-end ""))
>      (comment-dwim arg)))
>
> (setq myKeywords
>  `(
>   )
> )
>
> ;; define the major mode.
> (define-derived-mode jou-mode fundamental-mode
>   "you are in jou-mode"
>   (setq font-lock-defaults '(myKeywords))
>
>   (setq comment-start "/")
>
>   (define-key jou-mode-map [remap comment-dwim] 'jou-comment-dwim)
>
>   (modify-syntax-entry ?/ "< b" jou-mode-syntax-table)
>   (modify-syntax-entry ?\n "> b" jou-mode-syntax-table)
> )
> <--8---><--8---><--8---><--8---><--8---><--8---><--8---><--8---><--8---
>
> ><--8---><--8---><--8--->
>
> The comment syntax highlighting works, but I still have few questions.
>
> 1) Is the line (setq comment-start "/") which I have added really
> needed?

you don't need it.

> 2) I don't need the keywords, but if I remove the relevant entries in
> the jou-mode.el file
>    (i.e. lines 9-12, 17), the commented lines are no longer in red.

I'll have to take some time to know the tech details, but it's pretty
safe to jsut let your code be.

> 3) if the comment string "/" is in the middle of a line, like the
> division sign in an expression,
>    then the characters to the right of it are turned into red. Do you
> know how to avoid this?

if you want everything between / and newline char to be treated as
comment, than that is what your code has told emacs to do. If you want
to introduce some special case, then in short your comment syntax is a
complex one. As such, it cannot be implemented by using just syntax
table. You'll have to use emacs general mechanism for syntax coloring.
I'm not expert enough to give you solution off hand, and my
experiences with emacs syntax coloring mechanism is that it's quite
difficult and complex to learn.

Maybe someone else here can help.

Thanks & good luck.

  Xah
∑ http://xahlee.org/

reply via email to

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