From: Lars Ingebrigtsen Date: Sat, 3 Aug 2019 14:00:20 +0000 (+0200) Subject: Fix error message in replace-match for subexpressions X-Git-Tag: emacs-27.0.90~1733 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=18e163fd3455deaa30b1effd19f51a5094bc0885;p=emacs.git Fix error message in replace-match for subexpressions * src/search.c (Freplace_match): Output a more understandable error message when replacing a subexpression (bug#19208). --- diff --git a/src/search.c b/src/search.c index 2fa8b277195..0e2ae059e81 100644 --- a/src/search.c +++ b/src/search.c @@ -2404,6 +2404,12 @@ since only regular expressions have distinguished subexpressions. */) args_out_of_range (subexp, make_fixnum (search_regs.num_regs)); } + /* Check whether the subexpression to replace is greater than the + number of subexpressions in the regexp. */ + if (sub > 0 && search_regs.start[sub] == -1) + args_out_of_range (build_string ("Attempt to replace regexp subexpression that doesn't exist"), + subexp); + /* Sanity check to see whether the text to replace is present in the buffer/string. */ if (NILP (string))