From: Lars Ingebrigtsen <larsi@gnus.org>
To: Toby Cubitt <toby-dated-1593024851.318b83@dr-qubit.org>
Cc: 41793@debbugs.gnu.org
Subject: bug#41793: `comment-only-p' erroneously flags blank lines as comments
Date: Thu, 28 Jan 2021 07:11:07 +0100 [thread overview]
Message-ID: <871re54mmc.fsf@gnus.org> (raw)
In-Reply-To: <20200610185251.GA25375@bb84> (Toby Cubitt's message of "Wed, 10 Jun 2020 19:52:51 +0100")
Toby Cubitt <toby-dated-1593024851.318b83@dr-qubit.org> 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
next prev parent reply other threads:[~2021-01-28 6:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-10 17:53 bug#41793: `comment-only-p' erroneously flags blank lines as comments Toby Cubitt
2020-06-10 18:52 ` Toby Cubitt
2021-01-28 6:11 ` Lars Ingebrigtsen [this message]
2022-05-09 11:14 ` Lars Ingebrigtsen
2022-05-09 15:07 ` Drew Adams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=871re54mmc.fsf@gnus.org \
--to=larsi@gnus.org \
--cc=41793@debbugs.gnu.org \
--cc=toby-dated-1593024851.318b83@dr-qubit.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.