Subject: bug#21119: closed (Re: bug#21119: comment-dwim should have behavior on active, empty regions)

From: [email-masked] (GNU bug Tracking System)
Date: Tue, 01 Sep 2015 02:18:02 +0000

Your bug report

#21119: comment-dwim should have behavior on active, empty regions

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
21119: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=21119
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#21119: comment-dwim should have behavior on active, empty regions
From: Artur Malabarba <[email-masked]>
To: Zachary Kanfer <[email-masked]>
Cc: [email-masked]
Date: Tue, 1 Sep 2015 03:17:11 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

Fixed.

Just FYI, Zachary. Your patch did not apply. Did you create it with
git format-patch?

Subject: comment-dwim should have behavior on active, empty regions
From: Zachary Kanfer <[email-masked]>
To: [email-masked]
Date: Wed, 22 Jul 2015 16:37:42 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

This patch is for the function comment-dwim, which is bound to C-; by default.

Currently, when the region is not active, comment-dwim puts a comment
at the end of the line. When the region is active, comment-dwim
comments out the region by calling comment-or-uncomment-region.
However, when the region is active, but empty,
comment-or-uncomment-region does nothing; no text is inserted. I think
this last action (upon active, empty region) is a bug. If the active
region is empty, we should insert a comment at the end of the line, as
we do when there's no region.

This patch calls use-region-p to detect whether the region is active,
rather than checking mark-active transient-mark-mode explicitly. The
effect of this is, when the region is active, but empty, comment-dwim
now acts as though the region was not active -- it puts a comment at
the end of the line. Use-region-p does do the previous behavior (of
checking mark-active and transient-mark-mode) by calling
region-active-p.

The patch follows:

>From 6bdd96b07775c5c2fd0f3d6595b6655b4093dcf2 Mon Sep 17 00:00:00 2001
From: Zachary Kanfer <[email-masked]>
Date: Mon, 20 Jul 2015 01:36:56 -0400
Subject: [PATCH] Make comment-dwim treat empty regions as inactive.

When the region is active, but is empty (length 0), comment-dwim now
acts as though the region was not active; that is, it puts a comment
at the end of the line.
---
 lisp/newcomment.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/newcomment.el b/lisp/newcomment.el
index 172a563..8d17a69 100644
--- a/lisp/newcomment.el
+++ b/lisp/newcomment.el
@@ -1266,7 +1266,7 @@ Else, call `comment-indent'.
 You can configure `comment-style' to change the way regions are commented."
   (interactive "*P")
   (comment-normalize-vars)
-  (if (and mark-active transient-mark-mode)
+  (if (use-region-p)
       (comment-or-uncomment-region (region-beginning) (region-end) arg)
     (if (save-excursion (beginning-of-line) (not (looking-at "\\s-*$")))
     ;; FIXME: If there's no comment to kill on this line and ARG is
--
1.9.1