GNU bug report logs - #35600
27.0.50; uncomment-region fails correctly to reverse the action of comment-region.

Previous Next

Package: emacs;

Reported by: Alan Mackenzie <acm <at> muc.de>

Date: Mon, 6 May 2019 10:12:01 UTC

Severity: normal

Found in version 27.0.50

Done: Alan Mackenzie <acm <at> muc.de>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 35600 in the body.
You can then email your comments to 35600 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#35600; Package emacs. (Mon, 06 May 2019 10:12:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Alan Mackenzie <acm <at> muc.de>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 06 May 2019 10:12:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: bug-gnu-emacs <at> gnu.org
Subject: 27.0.50; uncomment-region fails correctly to reverse the action of
 comment-region.
Date: Mon, 6 May 2019 10:11:00 +0000
Hello, Emacs.

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)
    ^
  <tab>


(the first of these lines being indented by four spaces, the second by a
<tab>).

Mark the two lines, and execute M-x comment-region.  We get this:

    ;; (if (null bs-state)
    ;;  (ignore)
       ^
     <tab>

(where all the space is space characters except for the <tab> 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 <tab>

, there now being four spurious spaces before the <tab> 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.

-- 
Alan Mackenzie (Nuremberg, Germany).




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35600; Package emacs. (Tue, 07 May 2019 09:00:02 GMT) Full text and rfc822 format available.

Message #8 received at 35600 <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: 35600 <at> debbugs.gnu.org
Subject: [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
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)
>     ^
>   <tab>


> (the first of these lines being indented by four spaces, the second by a
> <tab>).

> Mark the two lines, and execute M-x comment-region.  We get this:

>     ;; (if (null bs-state)
>     ;;  (ignore)
>        ^
>      <tab>

> (where all the space is space characters except for the <tab> 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 <tab>

> , there now being four spurious spaces before the <tab> 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 <tab>,
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).




Reply sent to Alan Mackenzie <acm <at> muc.de>:
You have taken responsibility. (Fri, 10 May 2019 07:37:02 GMT) Full text and rfc822 format available.

Notification sent to Alan Mackenzie <acm <at> muc.de>:
bug acknowledged by developer. (Fri, 10 May 2019 07:37:02 GMT) Full text and rfc822 format available.

Message #13 received at 35600-done <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: 35600-done <at> debbugs.gnu.org
Subject: Re: bug#35600: 27.0.50; uncomment-region fails correctly to reverse
 the action of comment-region.
Date: Fri, 10 May 2019 07:36:28 +0000
The bug has been fixed in master.

-- 
Alan Mackenzie (Nuremberg, Germany).

On Mon, May 06, 2019 at 10:12:02 +0000, GNU bug Tracking System wrote:
> Thank you for filing a new bug report with debbugs.gnu.org.

> This is an automatically generated reply to let you know your message
> has been received.

> Your message is being forwarded to the package maintainers and other
> interested parties for their attention; they will reply in due course.

> Your message has been sent to the package maintainer(s):
>  bug-gnu-emacs <at> gnu.org

> If you wish to submit further information on this problem, please
> send it to 35600 <at> debbugs.gnu.org.

> Please do not send mail to help-debbugs <at> gnu.org unless you wish
> to report a problem with the Bug-tracking system.

> -- 
> 35600: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=35600
> GNU Bug Tracking System
> Contact help-debbugs <at> gnu.org with problems




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 07 Jun 2019 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 323 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.