From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Toby Cubitt Newsgroups: gmane.emacs.bugs Subject: bug#41793: `comment-only-p' erroneously flags blank lines as comments Date: Wed, 10 Jun 2020 19:52:51 +0100 Message-ID: <20200610185251.GA25375@bb84> References: <20200610175331.GA23889@bb84> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="113595"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/1.10.1 (2018-07-13) To: 41793@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jun 10 20:55:11 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jj5sV-000TP7-1i for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 10 Jun 2020 20:55:11 +0200 Original-Received: from localhost ([::1]:46628 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jj5sT-0002eE-Ub for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 10 Jun 2020 14:55:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55190) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jj5sM-0002du-Md for bug-gnu-emacs@gnu.org; Wed, 10 Jun 2020 14:55:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:52052) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jj5sM-0004T8-Cx for bug-gnu-emacs@gnu.org; Wed, 10 Jun 2020 14:55:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jj5sM-0000Qu-9f for bug-gnu-emacs@gnu.org; Wed, 10 Jun 2020 14:55:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Toby Cubitt Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 10 Jun 2020 18:55:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 41793 X-GNU-PR-Package: emacs Original-Received: via spool by 41793-submit@debbugs.gnu.org id=B41793.15918152541607 (code B ref 41793); Wed, 10 Jun 2020 18:55:02 +0000 Original-Received: (at 41793) by debbugs.gnu.org; 10 Jun 2020 18:54:14 +0000 Original-Received: from localhost ([127.0.0.1]:35365 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jj5ra-0000Pq-4g for submit@debbugs.gnu.org; Wed, 10 Jun 2020 14:54:14 -0400 Original-Received: from sanddollar.geekisp.com ([216.168.135.167]:9884) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jj5rX-0000Pa-Vn for 41793@debbugs.gnu.org; Wed, 10 Jun 2020 14:54:12 -0400 Original-Received: (qmail 29311 invoked by uid 1003); 10 Jun 2020 18:54:11 -0000 Original-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 Original-Received: by bb84.localdomain (Postfix, from userid 1000) id 882BDC2A4C; Wed, 10 Jun 2020 19:52:51 +0100 (BST) Content-Disposition: inline In-Reply-To: <20200610175331.GA23889@bb84> X-PGP-Key: http://www.dr-qubit.org/gpg-toby-pub.asc X-Delivery-Agent: TMDA/1.1.11 (Ladyburn) X-Primary-Address: toby@dr-qubit.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:181825 Archived-At: 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@cantab.net web: www.dr-qubit.org