From: Eli Zaretskii <eliz@gnu.org>
To: Gabriele Nicolardi <gabriele@medialab.sissa.it>,
Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 67124@debbugs.gnu.org
Subject: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer)
Date: Sun, 12 Nov 2023 11:48:17 +0200 [thread overview]
Message-ID: <83cywfuwta.fsf@gnu.org> (raw)
In-Reply-To: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> (message from Gabriele Nicolardi on Sat, 11 Nov 2023 20:40:27 +0100)
> Date: Sat, 11 Nov 2023 20:40:27 +0100
> From: Gabriele Nicolardi <gabriele@medialab.sissa.it>
>
> Hi, I'm resending the bug report trying to do better than the previous one.
Thanks. (In the future, please respond to the original bug number,
instead of creating a new bug report; I've merged them now.)
> I often type `,` (`comma`) to check the replacement. It happens that,
> some times, I get the error (e.g.):
>
> match-substitute-replacement: Args out of range: #<buffer *scratch*>,
> 1667, 1679
>
> The error doesn't happen if I type `y` (or `n`)
>
> Try this:
>
> (query-replace ",.\\footnote{" ".\\footnote{" nil)
>
> With the string ",.\footnote{" at the end of the buffer. To see the
> error "{" must be the last char in the buffer.
>
> (I see often this bug because I use "narrowing" a lot)
>
> Is it a known bug?
The kludgey solution in the patch below should fix this. Please see
if it indeed fixes your real-life use cases.
Stefan, any ideas for a better fix, or other comments? AFAIU, the
root cause of the bug was that we are using integers instead of
markers there, and that is because bug#31492 needs to preserve the
original match-start position when the search string is a regexp that
matches an empty string (in which case the match-start marker moves
together with the match-end marker instead of staying put).
diff --git a/lisp/replace.el b/lisp/replace.el
index eeac734..6a3f223 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -2642,8 +2642,11 @@ replace-match-maybe-edit
(replace-match newtext fixedcase literal)
;; `query-replace' undo feature needs the beginning of the match position,
;; but `replace-match' may change it, for instance, with a regexp like "^".
- ;; Ensure that this function preserves the match data (Bug#31492).
- (set-match-data match-data)
+ ;; Ensure that this function preserves the beginning of the match position
+ ;; (bug#31492). But we need to avoid clobbering the end of the match with
+ ;; the original match-end position, since `replace-match' could have made
+ ;; that incorrect or even invalid (bug#67124).
+ (set-match-data (list (car match-data) (nth 1 (match-data))))
;; `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)))
next prev parent reply other threads:[~2023-11-12 9:48 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 [this message]
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
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=83cywfuwta.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=67124@debbugs.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 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.