all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Xah Lee <xahlee@gmail.com>
To: help-gnu-emacs@gnu.org
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)	[thread overview]
Message-ID: <8acbfcb8-c833-465e-8708-407365784c6f@x6g2000prc.googlegroups.com> (raw)
In-Reply-To: b289a95f-d391-44e8-93ea-5065c8227067@24g2000yqm.googlegroups.com

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	other threads:[~2009-07-17  1:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-15 11:37 How to enable the syntax highlighting for comments within files having a specific extension? gento
2009-07-15 23:51 ` Xah Lee
2009-07-16 13:13   ` bj
2009-07-17  1:14     ` Xah Lee [this message]
2009-08-27 22:22     ` A.Politz
2009-08-27 20:57 ` pjb

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8acbfcb8-c833-465e-8708-407365784c6f@x6g2000prc.googlegroups.com \
    --to=xahlee@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.