diff options
author | Tino Calancha <tino.calancha@gmail.com> | 2018-06-03 23:28:24 +0900 |
---|---|---|
committer | Tino Calancha <tino.calancha@gmail.com> | 2018-06-03 23:28:24 +0900 |
commit | 031004e81b1507c4594ae253faaafcda31f253c8 (patch) | |
tree | 7f3c92e2169d93ee3f74facf5a4a24f8db6e1307 /lisp/replace.el | |
parent | 50c0624b2aecb9668505eb2cea3f30aecbf6d1ec (diff) | |
download | emacs-031004e81b1507c4594ae253faaafcda31f253c8.tar.gz |
Backport: Fix corner case in query-replace-regexp undo
This commit fixes Bug#31492.
* lisp/replace.el (replace-match-maybe-edit): Preserve match data.
* test/lisp/replace-tests.el (query-replace-undo-bug31492): Add test.
(cherry picked from commit bab73230d1be1fe394b7269c1365ef6fb1a5d9b3)
Diffstat (limited to 'lisp/replace.el')
-rw-r--r-- | lisp/replace.el | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/lisp/replace.el b/lisp/replace.el index d1eabb035d3..88da7e26cb0 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -2147,6 +2147,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))) |