From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: gabriele@medialab.sissa.it, 67124@debbugs.gnu.org
Subject: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer)
Date: Thu, 16 Nov 2023 11:15:56 -0500 [thread overview]
Message-ID: <jwv7cmhlm66.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <83o7ftpx1w.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 16 Nov 2023 16:55:39 +0200")
>> >> > ;; `replace-match' leaves point at the end of the replacement text,
>> >> > ;; so move point to the beginning when replacing backward.
>> >> > (when backward (goto-char (nth 0 match-data)))
>> >>
>> >> and (nth 0 match-data) == (match-beginning 0), no?
>> > See above: not exactly.
>>
>> I believe the numerical value of (nth 0 match-data) will be the same at
>> this point as that of (nth 0 (match-data)) because we just passed that
>> very value to `set-match-data`, and that is always equal
>> (numerically) to (match-beginning 0).
>> Since the only thing we do with that value is pass it immediately to
>> `goto-char`, it makes no difference if it's a marker or an integer, no?
>>
>> What am I missing?
>
> What are you trying to understand?
Why you're saying that in
;; `replace-match' leaves point at the end of the replacement text,
;; so move point to the beginning when replacing backward.
(when backward (goto-char (nth 0 match-data)))
it is not true that
and (nth 0 match-data) == (match-beginning 0), no?
Note: this is not directly related to your patch, since your patch did
not touch that line, AFAICT.
> What my kludge did is simply use a marker, so the adjusted position is
> not clobbered.
I don't see that. E.g. if you change your code from
(set-match-data (list (car match-data) (nth 1 (match-data))))
to
(set-match-data (list (car match-data) (nth 1 (match-data t))))
it fixes the problem just as well, AFAICT. And it could even be
replaced with:
(set-match-data (cons (car match-data) (cdr (match-data t))))
My understand is that what you patch does is use the match end as
adjusted by `replace-match` rather than the match end as provided by the
`match-end` argument (because that argument contains integers and hence
ends up pointing to the wrong place after the buffer was modified by
`replace-match`).
Basically, the purpose of the above `set-match-data` originally was to
correct the (match-beginning 0) info because `replace-match` adjusted it
incorrectly (i.e. it works around a bug in `update_search_regs`), but
while doing that it ended up messing up the (match-end 0), so your patch
refines that code so as to leave (match-end 0) unchanged while
correcting (match-beginning 0).
"use a marker kludge" would sound like an appropriate description of the
`advice-add` I sent to Grabriel, on the other hand.
Stefan
next prev parent reply other threads:[~2023-11-16 16:15 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-11 19:40 bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer) Gabriele Nicolardi
2023-11-12 9:48 ` Eli Zaretskii
2023-11-13 3:56 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-13 14:17 ` Eli Zaretskii
2023-11-16 14:29 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-16 14:55 ` Eli Zaretskii
2023-11-16 16:15 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-11-16 16:56 ` Eli Zaretskii
2023-11-16 18:01 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-16 18:34 ` Eli Zaretskii
2023-11-16 15:35 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-16 16:51 ` Eli Zaretskii
2023-11-16 18:23 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-18 10:18 ` Eli Zaretskii
2023-11-18 16:44 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-18 21:35 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
[not found] ` <ed11baa2-cf89-4a72-91d0-8f26c0af4126@medialab.sissa.it>
2023-11-13 14:06 ` Eli Zaretskii
2023-11-13 14:21 ` Dmitry Gutov
2023-11-13 14:38 ` Eli Zaretskii
2023-11-13 14:45 ` Dmitry Gutov
2023-11-13 15:39 ` Gabriele Nicolardi
2023-11-16 14:45 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-16 16:27 ` Gabriele Nicolardi
2023-11-15 13:18 ` Eli Zaretskii
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=jwv7cmhlm66.fsf-monnier+emacs@gnu.org \
--to=bug-gnu-emacs@gnu.org \
--cc=67124@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=gabriele@medialab.sissa.it \
--cc=monnier@iro.umontreal.ca \
/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).