From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#35600: [Patch]: Re: bug#35600: 27.0.50; uncomment-region fails correctly to reverse the action of comment-region. Date: Tue, 7 May 2019 08:59:53 +0000 Message-ID: <20190507085953.GA4671@ACM> References: <20190506101100.GA4300@ACM> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="61619"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.10.1 (2018-07-13) To: 35600@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue May 07 11:00:12 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hNvxL-000FrM-FV for geb-bug-gnu-emacs@m.gmane.org; Tue, 07 May 2019 11:00:11 +0200 Original-Received: from localhost ([127.0.0.1]:42652 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNvxK-0005dq-H9 for geb-bug-gnu-emacs@m.gmane.org; Tue, 07 May 2019 05:00:10 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:39359) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNvxE-0005dO-BS for bug-gnu-emacs@gnu.org; Tue, 07 May 2019 05:00:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNvxD-0007ui-8B for bug-gnu-emacs@gnu.org; Tue, 07 May 2019 05:00:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:44652) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNvxD-0007uZ-4S for bug-gnu-emacs@gnu.org; Tue, 07 May 2019 05:00:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hNvxC-0002mh-W4 for bug-gnu-emacs@gnu.org; Tue, 07 May 2019 05:00:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 07 May 2019 09:00:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35600 X-GNU-PR-Package: emacs Original-Received: via spool by 35600-submit@debbugs.gnu.org id=B35600.155721960110671 (code B ref 35600); Tue, 07 May 2019 09:00:02 +0000 Original-Received: (at 35600) by debbugs.gnu.org; 7 May 2019 09:00:01 +0000 Original-Received: from localhost ([127.0.0.1]:58196 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hNvxB-0002m3-1n for submit@debbugs.gnu.org; Tue, 07 May 2019 05:00:01 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:36855 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1hNvx8-0002ls-K2 for 35600@debbugs.gnu.org; Tue, 07 May 2019 04:59:59 -0400 Original-Received: (qmail 16276 invoked by uid 3782); 7 May 2019 08:59:54 -0000 Original-Received: from acm.muc.de (p4FE15AB1.dip0.t-ipconnect.de [79.225.90.177]) by colin.muc.de (tmda-ofmipd) with ESMTP; Tue, 07 May 2019 10:59:53 +0200 Original-Received: (qmail 4782 invoked by uid 1000); 7 May 2019 08:59:53 -0000 Content-Disposition: inline In-Reply-To: <20190506101100.GA4300@ACM> X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.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: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:158864 Archived-At: Hello, Emacs. On Mon, May 06, 2019 at 10:11:00 +0000, Alan Mackenzie wrote: > In the master branch: > With indent-tabs-mode t, and tab-width (say) 8, start off with the > following two line of Emacs lisp: > (if (null bs-state) > (ignore) > ^ > > (the first of these lines being indented by four spaces, the second by a > ). > Mark the two lines, and execute M-x comment-region. We get this: > ;; (if (null bs-state) > ;; (ignore) > ^ > > (where all the space is space characters except for the just > before "(ignore)"). > Now execute M-x uncomment-region. This should restore the region to > what it started as. Instead one gets: > (if (null bs-state) > (ignore) > ^^^^ ^ > SPCs > , there now being four spurious spaces before the preceding > "(ignore)". This is a bug. > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > In uncomment-region-default-1, the variable `spt' gets set to the result > of comment-search-forward, the ";" at the beginning of the comment on > the current line. The function then narrows to between `spt' and BO > next line. > In this narrowed region, the function removes the comment starter. > Because of the narrowing, it cannot take any account of the spaces at > the start of the line. > Possibly, uncomment-region needs to be amended so that that narrowing > includes any space preceding the comment starter, and that space gets > properly handled. Here is a patch which fixes the bug a little differently. After removing a comment starter, if there are obtrusive spaces left before a , they get removed: diff --git a/lisp/newcomment.el b/lisp/newcomment.el index 9d919ccbbe..ab2be080a3 100644 --- a/lisp/newcomment.el +++ b/lisp/newcomment.el @@ -1001,7 +1001,15 @@ uncomment-region-default-1 (re-search-forward sre (line-end-position) t)) (replace-match "" t t nil (if (match-end 2) 2 1))))) ;; Go to the end for the next comment. - (goto-char (point-max)))))) + (goto-char (point-max))) + ;; Remove any obtrusive spaces left preceding a tab at `spt'. + (when (and (eq (char-after spt) ?\t) (eq (char-before spt) ? ) + (> tab-width 0)) + (save-excursion + (goto-char spt) + (let* ((fcol (current-column)) + (slim (- (point) (mod fcol tab-width)))) + (delete-char (- (skip-chars-backward " " slim))))))))) (set-marker end nil)) (defun uncomment-region-default (beg end &optional arg) -- Alan Mackenzie (Nuremberg, Germany).