From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.bugs Subject: bug#41793: `comment-only-p' erroneously flags blank lines as comments Date: Thu, 28 Jan 2021 07:11:07 +0100 Message-ID: <871re54mmc.fsf@gnus.org> References: <20200610175331.GA23889@bb84> <20200610185251.GA25375@bb84> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38111"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 41793@debbugs.gnu.org To: Toby Cubitt Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jan 28 07:12:09 2021 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 1l50XJ-0009o8-Dg for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 28 Jan 2021 07:12:09 +0100 Original-Received: from localhost ([::1]:60184 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l50XI-0003Lh-Fx for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 28 Jan 2021 01:12:08 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34160) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l50XC-0003La-0j for bug-gnu-emacs@gnu.org; Thu, 28 Jan 2021 01:12:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:35281) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l50XB-0003Je-Pg for bug-gnu-emacs@gnu.org; Thu, 28 Jan 2021 01:12:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l50XB-0008MB-JM for bug-gnu-emacs@gnu.org; Thu, 28 Jan 2021 01:12:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Lars Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 28 Jan 2021 06:12:01 +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.161181428632074 (code B ref 41793); Thu, 28 Jan 2021 06:12:01 +0000 Original-Received: (at 41793) by debbugs.gnu.org; 28 Jan 2021 06:11:26 +0000 Original-Received: from localhost ([127.0.0.1]:46827 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l50WY-0008L8-MK for submit@debbugs.gnu.org; Thu, 28 Jan 2021 01:11:26 -0500 Original-Received: from quimby.gnus.org ([95.216.78.240]:58482) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l50WW-0008Ku-IR for 41793@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=; Original-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 ) id 1l50WK-0004y6-UV; Thu, 28 Jan 2021 07:11:13 +0100 X-Now-Playing: Tujiko Noriko's _Kuro (OST)_: "The Flood" In-Reply-To: <20200610185251.GA25375@bb84> (Toby Cubitt's message of "Wed, 10 Jun 2020 19:52:51 +0100") 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:198744 Archived-At: Toby Cubitt 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