From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Lawrence Mitchell Newsgroups: gmane.emacs.bugs Subject: bug#8150: 23.2; cperl-uncomment-region is NOT an inverse of cperl-comment-region Date: Thu, 03 Mar 2011 10:06:53 +0000 Message-ID: References: <878vwxgb07.fsf@cds.caltech.edu> <0aipw177lj.fsf@fencepost.gnu.org> <20110302203816.7e8e2fa1@smart> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1299148957 21031 80.91.229.12 (3 Mar 2011 10:42:37 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 3 Mar 2011 10:42:37 +0000 (UTC) To: bug-gnu-emacs@gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Mar 03 11:42:30 2011 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.69) (envelope-from ) id 1Pv5zC-0002mO-5C for geb-bug-gnu-emacs@m.gmane.org; Thu, 03 Mar 2011 11:42:22 +0100 Original-Received: from localhost ([127.0.0.1]:54050 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pv5uo-0008VM-Ay for geb-bug-gnu-emacs@m.gmane.org; Thu, 03 Mar 2011 05:37:50 -0500 Original-Received: from [140.186.70.92] (port=50377 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pv5tz-000870-QW for bug-gnu-emacs@gnu.org; Thu, 03 Mar 2011 05:37:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pv5tu-0002eL-Fa for bug-gnu-emacs@gnu.org; Thu, 03 Mar 2011 05:36:59 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:51650) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pv5tu-0002eH-CV for bug-gnu-emacs@gnu.org; Thu, 03 Mar 2011 05:36:54 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1Pv5Rx-0004da-Td; Thu, 03 Mar 2011 05:08:01 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: <878vwxgb07.fsf@cds.caltech.edu> Resent-From: Lawrence Mitchell Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 03 Mar 2011 10:08:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 8150 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by submit@debbugs.gnu.org id=B.129914684217779 (code B ref -1); Thu, 03 Mar 2011 10:08:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 3 Mar 2011 10:07:22 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Pv5RK-0004ci-9h for submit@debbugs.gnu.org; Thu, 03 Mar 2011 05:07:22 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Pv5RH-0004cU-J9 for submit@debbugs.gnu.org; Thu, 03 Mar 2011 05:07:20 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pv5RB-0005cM-73 for submit@debbugs.gnu.org; Thu, 03 Mar 2011 05:07:14 -0500 Original-Received: from lists.gnu.org ([199.232.76.165]:49040) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pv5RB-0005cI-4d for submit@debbugs.gnu.org; Thu, 03 Mar 2011 05:07:13 -0500 Original-Received: from [140.186.70.92] (port=48924 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pv5R9-0001F0-Rt for bug-gnu-emacs@gnu.org; Thu, 03 Mar 2011 05:07:12 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pv5R8-0005bl-5Z for bug-gnu-emacs@gnu.org; Thu, 03 Mar 2011 05:07:11 -0500 Original-Received: from lo.gmane.org ([80.91.229.12]:54689) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pv5R7-0005aq-Qs for bug-gnu-emacs@gnu.org; Thu, 03 Mar 2011 05:07:10 -0500 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1Pv5R4-0003QO-TT for bug-gnu-emacs@gnu.org; Thu, 03 Mar 2011 11:07:06 +0100 Original-Received: from e4300lm.epcc.ed.ac.uk ([129.215.63.156]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 03 Mar 2011 11:07:06 +0100 Original-Received: from wence by e4300lm.epcc.ed.ac.uk with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 03 Mar 2011 11:07:06 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 89 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: e4300lm.epcc.ed.ac.uk User-Agent: Gnus/5.110012 (No Gnus v0.12) Emacs/24.0.50 (gnu/linux) Cancel-Lock: sha1:37L4ehk22k6X4GTJrJeKiFoc7BQ= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Thu, 03 Mar 2011 05:08:01 -0500 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org 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:44561 Archived-At: Dima Kogan wrote: > I can and I do, but the current behavior seems wrong. If > (comment-region beg end -1) is no longer supported, it should generate > an error instead of succeeding badly. Should we simply call > (uncomment-region beg end 1) in that case? I can make the patch, but > would need to know what the current plan is. Note that the problem is that (uncomment-region A B 1) is not the inverse of (comment-region A B 1). Irrespective of the major mode in effect: emacs -Q C-x h C-1 M-x comment-region RET C-x h C-1 M-x uncomment-region RET Note how there is now a space at the beginning of every line in the *scratch* buffer. This is due to the following code in uncomment-region-default: | (if (null arg) (delete-region (point-min) (point)) | (skip-syntax-backward " ") | (delete-char (- numarg)) # foo bar ^ point is here when the above code is called. If an argument is supplied, arg is non-nil and so to delete the comment we first move backwards over whitespace and then delete as many comment characters as specified by the argument (1 in this case). This patch appears to do the right thing from my minimal testing, but I don't know if it will have any unfortunate side-effects: 2011-03-03 Lawrence Mitchell Make uncomment-region the inverse of comment-region. * newcomment.el (uncomment-region-default): Delete skipped-over whitespace if all comment characters have been removed. This makes M-1 M-x uncomment-region RET the inverse of M-1 M-x comment-region RET. Previously, commenting and then uncommenting a region with an argument would leave a space at the beginning of each line. diff --git a/lisp/newcomment.el b/lisp/newcomment.el index d88b76a..bcdc1e6 100644 --- a/lisp/newcomment.el +++ b/lisp/newcomment.el @@ -871,15 +871,20 @@ comment markers." (when (and sre (looking-at (concat "\\s-*\n\\s-*" srei))) (goto-char (match-end 0))) (if (null arg) (delete-region (point-min) (point)) - (skip-syntax-backward " ") - (delete-char (- numarg)) - (unless (or (bobp) - (save-excursion (goto-char (point-min)) - (looking-at comment-start-skip))) - ;; If there's something left but it doesn't look like - ;; a comment-start any more, just remove it. - (delete-region (point-min) (point)))) - + (let* ((opoint (point-marker)) + (nchar (skip-syntax-backward " "))) + (delete-char (- numarg)) + (unless (or (bobp) + (save-excursion (goto-char (point-min)) + (looking-at comment-start-skip))) + ;; If there's something left but it doesn't look like + ;; a comment-start any more, just remove it. + (delete-region (point-min) (point))) + (save-excursion + (goto-char (point-min)) + (unless (looking-at comment-start-skip) + (goto-char opoint) + (delete-char nchar))))) ;; Remove the end-comment (and leading padding and such). (goto-char (point-max)) (comment-enter-backward) ;; Check for special `=' used sometimes in comment-box. -- Lawrence Mitchell