[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how to deal with comment in a new lang mode
From: |
Kevin Rodgers |
Subject: |
Re: how to deal with comment in a new lang mode |
Date: |
Thu, 30 Oct 2008 20:46:27 -0600 |
User-agent: |
Thunderbird 2.0.0.17 (Macintosh/20080914) |
Xah 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.
I can't address your question, but I can suggest a minor simplification
of your current implementation:
(defun xlsl-comment-dwim (arg)
(interactive "*P")
(let ((comment-start "// ")
(comment-end ""))
(comment-dwim arg)))
This is also has the advantage of restoring the original binding of
the comment-start and comment-end variables, even if comment-dwim
signals an error.
Hope that helps,
--
Kevin Rodgers
Denver, Colorado, USA