diff options
| author | Tino Calancha | 2018-05-23 18:20:36 +0900 |
|---|---|---|
| committer | Tino Calancha | 2018-05-23 18:20:36 +0900 |
| commit | bab73230d1be1fe394b7269c1365ef6fb1a5d9b3 (patch) | |
| tree | 6a72e3b835d74781cfb878278aa5e944f90bf3b1 /lisp/replace.el | |
| parent | cc130d13d4b2b4c20d22401364f9814871819791 (diff) | |
| download | emacs-bab73230d1be1fe394b7269c1365ef6fb1a5d9b3.tar.gz emacs-bab73230d1be1fe394b7269c1365ef6fb1a5d9b3.zip | |
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.
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 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." | |||
| 2214 | noedit nil))) | 2214 | noedit nil))) |
| 2215 | (set-match-data match-data) | 2215 | (set-match-data match-data) |
| 2216 | (replace-match newtext fixedcase literal) | 2216 | (replace-match newtext fixedcase literal) |
| 2217 | ;; `query-replace' undo feature needs the beginning of the match position, | ||
| 2218 | ;; but `replace-match' may change it, for instance, with a regexp like "^". | ||
| 2219 | ;; Ensure that this function preserves the match data (Bug#31492). | ||
| 2220 | (set-match-data match-data) | ||
| 2217 | ;; `replace-match' leaves point at the end of the replacement text, | 2221 | ;; `replace-match' leaves point at the end of the replacement text, |
| 2218 | ;; so move point to the beginning when replacing backward. | 2222 | ;; so move point to the beginning when replacing backward. |
| 2219 | (when backward (goto-char (nth 0 match-data))) | 2223 | (when backward (goto-char (nth 0 match-data))) |