[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: comment-kill can't deal with following situation
From: |
lgfang |
Subject: |
Re: comment-kill can't deal with following situation |
Date: |
Fri, 29 Feb 2008 19:02:16 +0800 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.1 (berkeley-unix) |
Hi,
comment-kill is defined in newcomment.el. It is supposed to kill
comments (refer to its document). But it can't deal with the cases in
which there are more than one comment in a line. An example is:
--------8<----------------8<--------
void f(){
int i; /* this will be killed */ int j; /* oops, this
one won't be killed */
}
--------8<----------------8<--------
I check the code and think it is due to lack of loop. It seems that
following fix works. But maybe there are better fixes.
--------8<------Fixed comment-kill ----------8<--------
(defun comment-kill (arg)
"Kill the comment on this line, if any.
With prefix ARG, kill comments on that many lines starting with this one."
(interactive "P")
(comment-normalize-vars)
(dotimes (_ (prefix-numeric-value arg))
(save-excursion
(beginning-of-line)
(let ((line-num (line-number-at-pos))
(cs (comment-search-forward (line-end-position) t)))
(while cs
(goto-char cs)
(skip-syntax-backward " ")
(setq cs (point))
(comment-forward)
(kill-region cs (if (bolp) (1- (point)) (point)))
(indent-according-to-mode)
(when (= line-num (line-number-at-pos)) ; still in the line
(setq cs (comment-search-forward (line-end-position) t))))))
(if arg (forward-line 1))))
--------8<----------------8<--------
In GNU Emacs 22.1.1 (i386-mingw-nt5.1.2600) of 2007-06-02 on
RELEASE Windowing system distributor `Microsoft Corp.',
version 5.1.2600 configured using `configure --with-gcc
(3.4) --cflags -Ic:/gnuwin32/include'
Regards,
Fang, lungang
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: comment-kill can't deal with following situation,
lgfang <=