[Top][All Lists]

[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)


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:

void f(){
    int i; /* this will be killed */ int j; /* oops, this
                                               one won't be killed */

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")
  (dotimes (_ (prefix-numeric-value arg))
      (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))
          (kill-region cs (if (bolp) (1- (point)) (point)))
      (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))))

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'


Fang, lungang

reply via email to

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