unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Toby Cubitt <tsc25@cantab.net>
To: 41793@debbugs.gnu.org
Subject: bug#41793: `comment-only-p' erroneously flags blank lines as comments
Date: Wed, 10 Jun 2020 18:53:31 +0100	[thread overview]
Message-ID: <20200610175331.GA23889@bb84> (raw)

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@cantab.net
web:   www.dr-qubit.org





             reply	other threads:[~2020-06-10 17:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-10 17:53 Toby Cubitt [this message]
2020-06-10 18:52 ` bug#41793: `comment-only-p' erroneously flags blank lines as comments Toby Cubitt
2021-01-28  6:11   ` Lars Ingebrigtsen
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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200610175331.GA23889@bb84 \
    --to=tsc25@cantab.net \
    --cc=41793@debbugs.gnu.org \
    --cc=toby-dated-1593021285.3f7973@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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).