summaryrefslogtreecommitdiff
path: root/lisp/replace.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/replace.el')
-rw-r--r--lisp/replace.el4
1 files changed, 4 insertions, 0 deletions
diff --git a/lisp/replace.el b/lisp/replace.el
index 3503b656d9c..a17dd19b0d3 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -2214,6 +2214,10 @@ passed in. If LITERAL is set, no checking is done, anyway."
noedit nil)))
(set-match-data match-data)
(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)
;; `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)))