When I run query-replace* commands if I type ? I get this explanation of the function's options:

Type Space or ‘y’ to replace one match, Delete or ‘n’ to skip to next,
RET or ‘q’ to exit, Period to replace one match and exit,
Comma to replace but not move point immediately,
C-r to enter recursive edit (C-M-c to get out again),
C-w to delete match and recursive edit,
C-l to clear the screen, redisplay, and offer same replacement again,
! to replace all remaining matches in this buffer with no more questions,
^ to move point back to previous match,
u to undo previous replacement,
U to undo all replacements,
E to edit the replacement string.
In multi-buffer replacements type ‘Y’ to replace all remaining
matches in all remaining buffers with no more questions,
‘N’ to skip to the next buffer without replacing remaining matches
in the current buffer.

I often use 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 use "narrowing" a lot)

Is it a known bug?

My emacs version is GNU Emacs 26.3.

  • 1
    I can replicate in current versions of Emacs. M-x report-emacs-bug if there's not an existing bug report for it.
    – phils
    Commented Nov 10, 2023 at 12:12
  • When you report the bug, please provide a recipe to repro it that starts with emacs -Q (no init file).
    – Drew
    Commented Nov 10, 2023 at 17:30
  • 2
    @Drew I never reported a bug in my life! I did it now for the first time and I tried to do the best I can. I just posted the url of this issue.
    – Gabriele
    Commented Nov 10, 2023 at 17:40
  • Thanks for reporting the bug! But it's better if you include all relevant info in the bug thread itself, instead of just pointing here.
    – Drew
    Commented Nov 10, 2023 at 17:41
  • 1
    -Q causes Emacs to start without any init files (site or user), so if you can reproduce the bug in such a session, it shows that the bug is really an Emacs bug, rather than an init file bug.
    – NickD
    Commented Nov 10, 2023 at 21:31

1 Answer 1


It was indeed a bug. I believe it will be fixed in Emacs version 29.2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.