GNU bug report logs - #41793
`comment-only-p' erroneously flags blank lines as comments

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Toby Cubitt <toby-dated-1593021285.3f7973@HIDDEN>; Done: Lars Ingebrigtsen <larsi@HIDDEN>; Maintainer for emacs is bug-gnu-emacs@HIDDEN.
bug closed, send any further explanations to 41793 <at> debbugs.gnu.org and Toby Cubitt <toby-dated-1593021285.3f7973@HIDDEN> Request was from Lars Ingebrigtsen <larsi@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 41793 <at> debbugs.gnu.org:


Received: (at 41793) by debbugs.gnu.org; 9 May 2022 11:14:56 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon May 09 07:14:56 2022
Received: from localhost ([127.0.0.1]:56376 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1no1Lr-00089c-S0
	for submit <at> debbugs.gnu.org; Mon, 09 May 2022 07:14:56 -0400
Received: from quimby.gnus.org ([95.216.78.240]:40928)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <larsi@HIDDEN>) id 1no1Lq-00089M-0f
 for 41793 <at> debbugs.gnu.org; Mon, 09 May 2022 07:14:54 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org;
 s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:
 References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:
 Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender:
 Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:
 List-Subscribe:List-Post:List-Owner:List-Archive;
 bh=FILU1U/KbAscBi7qWuk2wMRh4nBXbj96KdRaM9P71NE=; b=fq4cCqWetl5ggtKtYLlxNvDeN9
 SPnOPbhAPgLXHD646cKz4b/dBZNXVRil3+i9FWnL3vpuK7fo6JdXaGMrqZdVcU8uCmQI6E/GtFWPY
 /E4LhZXV5GduC1SpfluAi92fJuiACws8Rk2bu0gKEcNML8QIZZ/7jU1SNyPeUpUFEkNA=;
Received: from [84.212.220.105] (helo=xo)
 by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.92) (envelope-from <larsi@HIDDEN>)
 id 1no1Lg-00055G-W4; Mon, 09 May 2022 13:14:47 +0200
From: Lars Ingebrigtsen <larsi@HIDDEN>
To: Toby Cubitt <toby-dated-1593024851.318b83@HIDDEN>
Subject: Re: bug#41793: `comment-only-p' erroneously flags blank lines as
 comments
References: <20200610175331.GA23889@bb84> <20200610185251.GA25375@bb84>
 <871re54mmc.fsf@HIDDEN>
X-Now-Playing: Grace Jones's _Living My Life_: "Inspiration"
Date: Mon, 09 May 2022 13:14:44 +0200
In-Reply-To: <871re54mmc.fsf@HIDDEN> (Lars Ingebrigtsen's message of "Thu,
 28 Jan 2021 07:11:07 +0100")
Message-ID: <87sfpj7yaj.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 @@CONTACT_ADDRESS@@ for details.
 Content preview: Lars Ingebrigtsen <larsi@HIDDEN> writes: >> Gah. That
 attempt
 breaks flagging of comments separated by >> whitespace-only lines. Maybe
 this? > > Do you have an example of when that fails? The test was 
 Content analysis details:   (-2.9 points, 5.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
 -1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%
 [score: 0.0000]
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 41793
Cc: 41793 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

Lars Ingebrigtsen <larsi@HIDDEN> writes:

>> Gah. That attempt breaks flagging of comments separated by
>> whitespace-only lines. Maybe this?
>
> Do you have an example of when that fails?

The test was

;; foo
;;       
;; bar

where comment-only-p would give the wrong results.

Anyway, I think it's ambiguous whether whitespace only should be a
comment or not.  The current algo considers this to be one comment:

;; foo

;; bar

And I think that's correct.  If we consider whitespace lines to not be
comments, this would change how our comment navigation commands work.

So there's some DWIM in this area, but I think how it currently works is
basically the way we want it to work, so I'm closing this bug report.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#41793; Package emacs. Full text available.

Message received at 41793 <at> debbugs.gnu.org:


Received: (at 41793) by debbugs.gnu.org; 28 Jan 2021 06:11:26 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Jan 28 01:11:26 2021
Received: from localhost ([127.0.0.1]:46827 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1l50WY-0008L8-MK
	for submit <at> debbugs.gnu.org; Thu, 28 Jan 2021 01:11:26 -0500
Received: from quimby.gnus.org ([95.216.78.240]:58482)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <larsi@HIDDEN>) id 1l50WW-0008Ku-IR
 for 41793 <at> debbugs.gnu.org; Thu, 28 Jan 2021 01:11:21 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org;
 s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:
 References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:
 Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender:
 Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:
 List-Subscribe:List-Post:List-Owner:List-Archive;
 bh=rx3N39X5GFxeYmYIaF9EikLUMV2Xcl0ezOscD+sLOBw=; b=BPwQBhJP+AWfkxw2yqbPaoXaUz
 ToVW5z7D97jTt3zQxuam0YBi7SXNe6AgKztTUgSGC18BK7nfYhmCpNlTko6gQ+M0G/mRpT4T22DpU
 i4qApmpcxy6zbJnOOgIYkFxWDnvTTSt7fv2cmdj+Xrngq/qkgspjIzmTxeLrsPJv2TEs=;
Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=xo)
 by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.92) (envelope-from <larsi@HIDDEN>)
 id 1l50WK-0004y6-UV; Thu, 28 Jan 2021 07:11:13 +0100
From: Lars Ingebrigtsen <larsi@HIDDEN>
To: Toby Cubitt <toby-dated-1593024851.318b83@HIDDEN>
Subject: Re: bug#41793: `comment-only-p' erroneously flags blank lines as
 comments
References: <20200610175331.GA23889@bb84> <20200610185251.GA25375@bb84>
X-Now-Playing: Tujiko Noriko's _Kuro (OST)_: "The Flood"
Date: Thu, 28 Jan 2021 07:11:07 +0100
In-Reply-To: <20200610185251.GA25375@bb84> (Toby Cubitt's message of "Wed, 10
 Jun 2020 19:52:51 +0100")
Message-ID: <871re54mmc.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 @@CONTACT_ADDRESS@@ for details.
 Content preview: Toby Cubitt <toby-dated-1593024851.318b83@HIDDEN>
 writes:
 > Gah. That attempt breaks flagging of comments separated by whitespace-only
 lines. Maybe this? > > (defun comment-only-p (beg end) > "Return non-nil
 if the text between BEG and END is all comments." [...] 
 Content analysis details:   (-2.9 points, 5.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
 -1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%
 [score: 0.0000]
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 41793
Cc: 41793 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Toby Cubitt <toby-dated-1593024851.318b83@HIDDEN> writes:

> Gah. That attempt breaks flagging of comments separated by whitespace-only lines. Maybe this?
>
> (defun comment-only-p (beg end)
>   "Return non-nil if the text between BEG and END is all comments."
>   (if (string-blank-p (buffer-substring beg end)) nil
>     (save-excursion
>       (goto-char beg)
>       (comment-forward (point-max))
>       (<= end (point)))))

I don't think that can be correct...  for instance, it'll return nil on
this C comment:

/*
|

*/

> This fix successfully makes `comment-or-uncomment-region' call
> `comment-region' when fed empty lines, instead of calling
> `uncomment-region' (which seems wrong).
>
> It doesn't fix the main issue I was trying to address, namely that
> `comment-or-uncomment-region' fails to comment out a region consisting
> only of blank lines, even when `comment-empty-lines' is t. Without the
> above fix, it calls `uncomment-region' which does nothing as there's
> nothing to comment. With the above fix, it calls `comment-region'. But
> the latter refuses to comment out the lines, throwing a "Nothing to
> comment" error.
>
> Fixing that (assuming it's considered a bug) would require more
> changes to `comment-region-default' and `comment-region-internal'.
>
> The use-case for this was editing a LaTeX document, where empty lines
> are semantically significant (they demark paragraph breaks). It's
> fairly common (especially when editing co-authored documents) to
> comment out the empty lines in order to run two paragraphs together,
> whilst keeping the commented-out empty lines in the source so it's
> easy to revert.

Right -- `M-x comment-region' on a blank region will just say "Nothing
to comment" here.  Which makes sense in most modes, but not in LaTeX
mode, I think.

I've now fixed `M-x comment-region' for blank lines in `latex-mode' in
Emacs 28, I think, but `M-x comment-or-uncomment-region' still doesn't
work because `comment-only-p' is, as you say, wrong.  Your first
attempt looked like it had promise, but then you said:

> Gah. That attempt breaks flagging of comments separated by
> whitespace-only lines. Maybe this?

Do you have an example of when that fails?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#41793; Package emacs. Full text available.

Message received at 41793 <at> debbugs.gnu.org:


Received: (at 41793) by debbugs.gnu.org; 10 Jun 2020 18:54:14 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Jun 10 14:54:14 2020
Received: from localhost ([127.0.0.1]:35365 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1jj5ra-0000Pq-4g
	for submit <at> debbugs.gnu.org; Wed, 10 Jun 2020 14:54:14 -0400
Received: from sanddollar.geekisp.com ([216.168.135.167]:9884)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <toby-dated-1593024851.318b83@HIDDEN>)
 id 1jj5rX-0000Pa-Vn
 for 41793 <at> debbugs.gnu.org; Wed, 10 Jun 2020 14:54:12 -0400
Received: (qmail 29311 invoked by uid 1003); 10 Jun 2020 18:54:11 -0000
Received: from bb84.localdomain (localhost.geekisp.com [127.0.0.1]) by
 localhost.geekisp.com (tmda-ofmipd) with ESMTP;
 Wed, 10 Jun 2020 14:54:04 -0400
Received: by bb84.localdomain (Postfix, from userid 1000)
 id 882BDC2A4C; Wed, 10 Jun 2020 19:52:51 +0100 (BST)
Date: Wed, 10 Jun 2020 19:52:51 +0100
To: 41793 <at> debbugs.gnu.org
Subject: Re: bug#41793: `comment-only-p' erroneously flags blank lines as
 comments
Message-ID: <20200610185251.GA25375@bb84>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20200610175331.GA23889@bb84>
X-PGP-Key: http://www.dr-qubit.org/gpg-toby-pub.asc
User-Agent: Mutt/1.10.1 (2018-07-13)
X-Delivery-Agent: TMDA/1.1.11 (Ladyburn)
From: Toby Cubitt <toby-dated-1593024851.318b83@HIDDEN>
X-Primary-Address: toby@HIDDEN
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 41793
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

On Wed, Jun 10, 2020 at 06:53:31PM +0100, Toby Cubitt wrote:
> In GNU Emacs 26.3 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.16)
>  of 2020-04-28
> 
> On the following text, with point at |
> (comment-only-p (point) (1+ (point)))
> returns t when it should probably return nil:
> 
> "
> |
> 
> test"
> 
> This impacts commands like `comment-or-uncomment-region'.
> 
> This is because the current implementation of `comment-only-p' fails to check the return value of (comment-forward):
> 
> The correct implementation should probably be:
[snip]

Gah. That attempt breaks flagging of comments separated by whitespace-only lines. Maybe this?

(defun comment-only-p (beg end)
  "Return non-nil if the text between BEG and END is all comments."
  (if (string-blank-p (buffer-substring beg end)) nil
    (save-excursion
      (goto-char beg)
      (comment-forward (point-max))
      (<= end (point)))))

This fix successfully makes `comment-or-uncomment-region' call `comment-region' when fed empty lines, instead of calling `uncomment-region' (which seems wrong).

It doesn't fix the main issue I was trying to address, namely that `comment-or-uncomment-region' fails to comment out a region consisting only of blank lines, even when `comment-empty-lines' is t. Without the above fix, it calls `uncomment-region' which does nothing as there's nothing to comment. With the above fix, it calls `comment-region'. But the latter refuses to comment out the lines, throwing a "Nothing to comment" error.

Fixing that (assuming it's considered a bug) would require more changes to `comment-region-default' and `comment-region-internal'.

The use-case for this was editing a LaTeX document, where empty lines are semantically significant (they demark paragraph breaks). It's fairly common (especially when editing co-authored documents) to comment out the empty lines in order to run two paragraphs together, whilst keeping the commented-out empty lines in the source so it's easy to revert.

Best,
Toby
-- 
Dr T. S. Cubitt
Reader (Associate Professor) in Quantum Information
Royal Society University Research Fellow
Department of Computer Science
University College London

email: tsc25@HIDDEN
web:   www.dr-qubit.org




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#41793; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 10 Jun 2020 18:01:26 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Jun 10 14:01:26 2020
Received: from localhost ([127.0.0.1]:35299 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1jj52T-0007T2-UR
	for submit <at> debbugs.gnu.org; Wed, 10 Jun 2020 14:01:26 -0400
Received: from lists.gnu.org ([209.51.188.17]:53022)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <tsc25@HIDDEN>) id 1jj52R-0007Su-Tn
 for submit <at> debbugs.gnu.org; Wed, 10 Jun 2020 14:01:24 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:42514)
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <tsc25@HIDDEN>) id 1jj52R-00066O-Ln
 for bug-gnu-emacs@HIDDEN; Wed, 10 Jun 2020 14:01:23 -0400
Received: from sanddollar.geekisp.com ([216.168.135.167]:45176)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256)
 (Exim 4.90_1) (envelope-from <tsc25@HIDDEN>) id 1jj52Q-0001s3-SD
 for bug-gnu-emacs@HIDDEN; Wed, 10 Jun 2020 14:01:23 -0400
Received: (qmail 11990 invoked by uid 1003); 10 Jun 2020 17:54:46 -0000
Received: from bb84.localdomain (localhost.geekisp.com [127.0.0.1]) by
 localhost.geekisp.com (tmda-ofmipd) with ESMTP;
 Wed, 10 Jun 2020 13:54:44 -0400
Received: by bb84.localdomain (Postfix, from userid 1000)
 id 3C2DFC2A4C; Wed, 10 Jun 2020 18:53:31 +0100 (BST)
Date: Wed, 10 Jun 2020 18:53:31 +0100
To: bug-gnu-emacs@HIDDEN
Subject: `comment-only-p' erroneously flags blank lines as comments
Message-ID: <20200610175331.GA23889@bb84>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
User-Agent: Mutt/1.10.1 (2018-07-13)
X-Delivery-Agent: TMDA/1.1.11 (Ladyburn)
From: Toby Cubitt <tsc25@HIDDEN>
X-Primary-Address: toby@HIDDEN
Received-SPF: neutral client-ip=216.168.135.167; envelope-from=tsc25@HIDDEN;
 helo=sanddollar.geekisp.com
X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/10 13:54:40
X-ACL-Warn: Detected OS   = OpenBSD 4.x-5.x [fuzzy]
X-Spam_score_int: -10
X-Spam_score: -1.1
X-Spam_bar: -
X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001,
 SPF_NEUTRAL=0.779, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN
X-Spam_action: no action
X-Spam-Score: -1.6 (-)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Reply-To: Toby Cubitt <toby-dated-1593021285.3f7973@HIDDEN>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.6 (--)

In GNU Emacs 26.3 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.16)
 of 2020-04-28

On the following text, with point at |
(comment-only-p (point) (1+ (point)))
returns t when it should probably return nil:

"
|

test"

This impacts commands like `comment-or-uncomment-region'.

This is because the current implementation of `comment-only-p' fails to check the return value of (comment-forward):

(defun comment-only-p (beg end)
  "Return non-nil if the text between BEG and END is all comments."
  (save-excursion
    (goto-char beg)
    (comment-forward (point-max))
    (<= end (point))))

The correct implementation should probably be:

(defun comment-only-p (beg end)
  "Return non-nil if the text between BEG and END is all comments."
  (save-excursion
    (goto-char beg)
    (and (comment-forward (point-max))
         (<= end (point)))))

Tested on 26.3, but implementation of `comment-only-p' is unchanged in latest git.

Cheers,
Toby
-- 
Dr T. S. Cubitt
Reader (Associate Professor) in Quantum Information
Royal Society University Research Fellow
Department of Computer Science
University College London

email: tsc25@HIDDEN
web:   www.dr-qubit.org




Acknowledgement sent to Toby Cubitt <toby-dated-1593021285.3f7973@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#41793; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Mon, 9 May 2022 11:30:01 UTC

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