From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: lgfang Newsgroups: gmane.emacs.bugs Subject: Re: comment-kill can't deal with following situation Date: Mon, 03 Mar 2008 20:04:29 +0800 Message-ID: <86fxv8ui7m.fsf@163.com> References: <198A33EB1E9E344EBC566802C7761D6B4ACE3C@CNSHGSMBS04.ad4.ad.alcatel.com> <86tzjsqb47.fsf@163.com> <86hcfps0c2.fsf@163.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1204548829 16848 80.91.229.12 (3 Mar 2008 12:53:49 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 3 Mar 2008 12:53:49 +0000 (UTC) Cc: bug-gnu-emacs@gnu.org, lgfang To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Mar 03 13:54:12 2008 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1JWAAy-00080G-1M for geb-bug-gnu-emacs@m.gmane.org; Mon, 03 Mar 2008 13:53:52 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JWAAR-0004KX-3T for geb-bug-gnu-emacs@m.gmane.org; Mon, 03 Mar 2008 07:53:19 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JWAAM-0004JE-D6 for bug-gnu-emacs@gnu.org; Mon, 03 Mar 2008 07:53:14 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JWAAH-0004AI-7q for bug-gnu-emacs@gnu.org; Mon, 03 Mar 2008 07:53:13 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JWAAH-00049y-19 for bug-gnu-emacs@gnu.org; Mon, 03 Mar 2008 07:53:09 -0500 Original-Received: from m12-11.163.com ([220.181.12.11]) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1JWAAF-0005NF-Kf for bug-gnu-emacs@gnu.org; Mon, 03 Mar 2008 07:53:08 -0500 Original-Received: from fbbox (unknown [122.4.109.212]) by smtp7 (Coremail) with SMTP id C8CowLDrUk7u6ctHyY44JQ==.29856S2; Mon, 03 Mar 2008 20:07:22 +0800 (CST) In-Reply-To: (Stefan Monnier's message of "Sun\, 02 Mar 2008 16\:42\:17 -0500") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (berkeley-unix) X-Coremail-Antispam: 1Uf129KBjvJXoWxJF48WFy7Xr4DJryDuF18Grg_yoW5Zr45pF 4vvrWrArn5ZF13AFykZa1xua4Ig34kJrW5ZF9Y9rZ3AF9Fq3s29rWfK345ArZrCrW8Xr40 gw17KrZxWw15t3DanT9S1TB71UUUUUUv73VFW2AGmfu7bjvjm3AaLaJ3UjIYCTnIWjp_UU U0txkFs20EY4vE8sxKj4xv1wCY1Ik26cxK6x8YrwAqx4xG64xvF2IEw4CE5I8CrVC2j2Wl 14x267AKxVWUJVW8JwAFxVCF77xC6IxKo4kEV4yl1I0EscIYIxCEI4klw4CSwwAFIxvE14 AKwVWUJVWUGwAq048E620vw7xCY7CEYx808205XwAq048E620vw7xCY7CE4x8GYI0EYx1l Yx0E2Ix0cI8IcVAFwI0_JrI_JrylYx0Ex4A2jsIE14v26r1j6r4UMx02cVCv0xWlc2xSY4 AK67AK6ryUMxkI7II2jI8vz4vEwIxGrwCF72vE52k0Y41lx4CE17CEb7AF67AKxVWUXVWU AwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8Jw CI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r1j6r4UM7k0a2IF 6r1UM7kC6x804xJvcSsGvfC2KfnxnUUI43ZEXa7IU8Ha0tUUUUU== X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) X-Greylist: delayed 2734 seconds by postgrey-1.27 at monty-python; Mon, 03 Mar 2008 07:53:07 EST X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:17642 Archived-At: >>>>> "Stefan" == Stefan Monnier writes: Stefan> If you do not provide a prefix arg, comment-kill should Stefan> only kill 1 comment. Indeed when providing a prefix arg, >> The document says: >> Kill the comment on this line, if any. With prefix ARG, kill >> comments on that many lines starting with this one. >> So, take following C code for example: int j; /* comment 1 */ >> int k; /* comment 2*/ >> I think comment-kill should kill both comment 1 and comment 2 >> even without prefix ARG. Stefan> Here I disagree. I find it more useful to only kill one Stefan> comment at a time (you can always choose to run the Stefan> command 2 times, but you cannot run it 1/2 a time). Also I agree with you. I didn't think of that. So, it is not a bug. I just misunderstood the document. Stefan> the docstring says "kill *the comment* on this line", Stefan> which admittedly is ambiguous when there are more than 1 Stefan> comments, but indicates a clear intention to only kill 1 Stefan> comment. Maybe need to update document ? :) Stefan> So please reply to my previous request: Stefan> I don't know of anybody who uses the prefix arg of Stefan> comment-kill, so if you could explain how you use it, it Stefan> might help decide what the behavior should be. In case you are interested, I'm NOT calling comment-kill interactively. I wrote a elisp script to count NCSL. The basic idea is to delete all comment lines using comment-kill and delete all blank lines using flush-lines. Then, the number of lines is just the number of NCSL. (let ((file nil) (sum 0)) (condition-case nil (while (setq file (read-string "")) (find-file file) (let ((buffer-read-only nil)) (goto-char (point-min)) (comment-kill (line-number-at-pos (point-max))) (flush-lines "^[[:blank:]]*$" (point-min) (point-max)) (let ((linum (- (line-number-at-pos (point-max)) 1))) ;; -1 since always end with empty line (princ (format "%d %s\n" linum file)) (setq sum (+ sum linum)))) (kill-buffer nil)) (error (princ (format "%s total\n" sum))))) But it turns out that that script is slow and in-correct. At last, I end up with something like following: (require 'hideif) (require 'newcomment) (let ((file nil) (sum 0) (ncsl 0)) (condition-case nil (while (setq file (read-string "")) ; for each file (find-file file) (setq ncsl 0) ;; for C/c++ files, hide if 0 (when (or (equal 'c-mode major-mode) (equal 'c++-mode major-mode)) (goto-char (point-min)) (while (re-search-forward "^[ \t]*#if[ \t]*0" nil t) (hide-ifdef-block))) (goto-char (point-min)) (while (not (eobp)) ;; suppose there won't be 10000 consecutive comments (forward-comment 10000) (setq ncsl (+ 1 ncsl)) ;; In case a comment starts at current line and spans several ;; lines. (let* ((eol (line-end-position)) (cs (comment-search-forward eol t))) (while cs (goto-char cs) (forward-comment 10000) (setq cs (comment-search-forward eol t))) (unless (> (point) eol) ; unless already a new line (forward-visible-line 1)))) (setq sum (+ sum ncsl)) (kill-buffer nil) (princ (format "%d %s\n" ncsl file))) (error (princ (format "%s total\n" sum))))) -- Fang, lungang