From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Zachary Kanfer Newsgroups: gmane.emacs.bugs Subject: bug#21119: comment-dwim should have behavior on active, empty regions Date: Wed, 22 Jul 2015 16:37:42 -0400 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1437597557 31853 80.91.229.3 (22 Jul 2015 20:39:17 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 22 Jul 2015 20:39:17 +0000 (UTC) To: 21119@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jul 22 22:39:09 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZI0nE-0007Ed-K5 for geb-bug-gnu-emacs@m.gmane.org; Wed, 22 Jul 2015 22:39:08 +0200 Original-Received: from localhost ([::1]:38148 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZI0nD-000673-PK for geb-bug-gnu-emacs@m.gmane.org; Wed, 22 Jul 2015 16:39:07 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47521) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZI0n9-00066f-K8 for bug-gnu-emacs@gnu.org; Wed, 22 Jul 2015 16:39:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZI0n8-00023C-Fz for bug-gnu-emacs@gnu.org; Wed, 22 Jul 2015 16:39:03 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:55219) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZI0n8-00022S-9u for bug-gnu-emacs@gnu.org; Wed, 22 Jul 2015 16:39:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1ZI0n8-0000um-0j for bug-gnu-emacs@gnu.org; Wed, 22 Jul 2015 16:39:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Zachary Kanfer Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 22 Jul 2015 20:39:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 21119 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.14375974903454 (code B ref -1); Wed, 22 Jul 2015 20:39:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 22 Jul 2015 20:38:10 +0000 Original-Received: from localhost ([127.0.0.1]:56665 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZI0mI-0000te-Ca for submit@debbugs.gnu.org; Wed, 22 Jul 2015 16:38:10 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:33783) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZI0mG-0000tQ-AY for submit@debbugs.gnu.org; Wed, 22 Jul 2015 16:38:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZI0mF-0001kV-8k for submit@debbugs.gnu.org; Wed, 22 Jul 2015 16:38:08 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:55202) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZI0mF-0001kR-5s for submit@debbugs.gnu.org; Wed, 22 Jul 2015 16:38:07 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47282) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZI0mD-0005yl-UQ for bug-gnu-emacs@gnu.org; Wed, 22 Jul 2015 16:38:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZI0mC-0001k4-KV for bug-gnu-emacs@gnu.org; Wed, 22 Jul 2015 16:38:05 -0400 Original-Received: from mail-oi0-x231.google.com ([2607:f8b0:4003:c06::231]:35507) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZI0mC-0001jQ-Fp for bug-gnu-emacs@gnu.org; Wed, 22 Jul 2015 16:38:04 -0400 Original-Received: by oihq81 with SMTP id q81so152171233oih.2 for ; Wed, 22 Jul 2015 13:38:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=IeIMQlXkeMlKoI5+QulCq5tYQiF4ZoArLFAZXNpvbI8=; b=iVedz+gjld9Otzy4UUk+gV+ye9q10/jvTLuw19YVhHUE0PXdmZ7U4N1GUAVq6xrnuY vWsoG3zHsanPQ1TwO57EsZvVDAk2YWADkSEsO0UMKK/vIIfNyWaSnq5oruA7soJ/C2uP ljZwUFgz7epT486CA0QEzj1ZvpgdujszzWW4dMrP47GHnhjbFrJtzOpqWg/h94eba7FM bfdcmUIAqeNupl2IpQXoCVGPxuGchTQrzm7aA/VlQjhNmtrbotwySbjD82whL76U60Qe bkFdcXG1FuDALiqMQ9EUp5ZdhOkBx8zCPBQ9FvLUbyg8OM2fdKwMpIErGw4zD5KgBWiD t6YQ== X-Received: by 10.202.93.66 with SMTP id r63mr4320800oib.5.1437597482153; Wed, 22 Jul 2015 13:38:02 -0700 (PDT) Original-Received: by 10.76.5.6 with HTTP; Wed, 22 Jul 2015 13:37:42 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x 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: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:105084 Archived-At: 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 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