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

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

Re: how to deal with comment in a new lang mode


From: rgb
Subject: Re: how to deal with comment in a new lang mode
Date: Fri, 31 Oct 2008 07:10:02 -0700 (PDT)
User-agent: G2/1.0

On Oct 30, 3:59 pm, Xah <xah...@gmail.com> wrote:
> when writing a new language mode, how can one make comment-dwim work?
>
> i can of course code my own functions dealing with comments, but i
> think it is better to use the facilities provided in newcomment.el?
>
> right now i have:
>
> (defun xlsl-comment-dwim (arg)
>   (interactive "*P")
>   (let ((comment-start-orig comment-start)
>         (comment-end-orig comment-end))
>     (setq comment-start "// ")
>     (setq comment-end "")
>     (comment-dwim arg)
>
>     (setq comment-start comment-start-orig)
>     (setq comment-end comment-end-orig)
> ))
>
> and
>
>   (define-key xlsl-mode-map [remap comment-dwim] 'xlsl-comment-dwim)
>
> this works fine when typing the shortcut for comment-dwim on a empty
> line to insert comment. But doesnt work as expected when the line is
> already a comment. (it does nothing)
>
> any advice apprecated for dealing with comments in a new lang mode.
>
> Thanks.
>
> PS if it matters, i also have my syntax table defined:
>
> (defvar xlsl-mode-syntax-table
>   (let ((synTable (make-syntax-table)))
>     (modify-syntax-entry ?\/ ". 12b" synTable)
>     (modify-syntax-entry ?\n "> b" synTable)
>
>     (modify-syntax-entry ?< "()" synTable)
>     (modify-syntax-entry ?> ")(" synTable)
>     synTable
>     )
>   "Syntax table for `xlsl-mode'."
> )
>
> The lsl has “// ...” as comment but not “/* ... */”. I dont want it to
> be derived mode of c-mode though atm ...
>
>   Xah
>http://xahlee.org/
>
>

Comment DWIM uses the variable comment-start for EOL terminated
comments.
If comments must be explicitly terminated then set comment-end.
(set (make-local-variable 'comment-start) "#")
See newcomment.el



reply via email to

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