Subject: bug#19208: replace-match unhelpful error message

From: [email-masked] (Phillip Lord)
Date: Fri, 28 Nov 2014 17:00:15 +0000

Occurs in Emacs 24.3 and trunk

Running this code in *scratch* buffer

(progn
  (goto-char (point-min))
  (re-search-forward "This")
  (replace-match "That" nil nil nil))

Now undo and run this code

(progn
  (goto-char (point-min))
  (re-search-forward "This")
  (replace-match "That" nil nil nil 1))

This causes the following error.

progn: Args out of range: -1, -1

The error is caused because I have asked for a subexp that doesn't exist in
the regexp. A programmer error for sure, but the Args out of range error seems
rather unfriendly to me, especially as I have no idea where the -1, or
-1 has come from.

"Attempt to replace regexp subexpression that doesn't exist", for
example, would be nicer.