diff options
| author | Eli Zaretskii | 2023-11-15 15:15:35 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2023-11-15 15:15:35 +0200 |
| commit | 8b458aea86ccbba255cbc5e97d6426df1e8bc6d9 (patch) | |
| tree | 6d71622da71f896ecddc78f26c599ac3a19e555c | |
| parent | 8fd26c03070dcf786276ea3a939ef74bfa05f5cb (diff) | |
| download | emacs-8b458aea86ccbba255cbc5e97d6426df1e8bc6d9.tar.gz emacs-8b458aea86ccbba255cbc5e97d6426df1e8bc6d9.zip | |
Fix query-replace at EOB
* lisp/replace.el (replace-match-maybe-edit): Avoid clobbering
match-data with outdated buffer position. (Bug#67124)
| -rw-r--r-- | lisp/replace.el | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/lisp/replace.el b/lisp/replace.el index 6b06e48c384..7fec54ecb27 100644 --- a/lisp/replace.el +++ b/lisp/replace.el | |||
| @@ -2644,8 +2644,11 @@ passed in. If LITERAL is set, no checking is done, anyway." | |||
| 2644 | (replace-match newtext fixedcase literal) | 2644 | (replace-match newtext fixedcase literal) |
| 2645 | ;; `query-replace' undo feature needs the beginning of the match position, | 2645 | ;; `query-replace' undo feature needs the beginning of the match position, |
| 2646 | ;; but `replace-match' may change it, for instance, with a regexp like "^". | 2646 | ;; but `replace-match' may change it, for instance, with a regexp like "^". |
| 2647 | ;; Ensure that this function preserves the match data (Bug#31492). | 2647 | ;; Ensure that this function preserves the beginning of the match position |
| 2648 | (set-match-data match-data) | 2648 | ;; (bug#31492). But we need to avoid clobbering the end of the match with |
| 2649 | ;; the original match-end position, since `replace-match' could have made | ||
| 2650 | ;; that incorrect or even invalid (bug#67124). | ||
| 2651 | (set-match-data (list (car match-data) (nth 1 (match-data)))) | ||
| 2649 | ;; `replace-match' leaves point at the end of the replacement text, | 2652 | ;; `replace-match' leaves point at the end of the replacement text, |
| 2650 | ;; so move point to the beginning when replacing backward. | 2653 | ;; so move point to the beginning when replacing backward. |
| 2651 | (when backward (goto-char (nth 0 match-data))) | 2654 | (when backward (goto-char (nth 0 match-data))) |