aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTino Calancha2019-09-09 08:21:18 +0200
committerTino Calancha2019-09-09 08:21:18 +0200
commit30c4f35a6fc8a6507930923766c3126ac1c2063f (patch)
tree59127e9f50d95fa2b1767674ec99203a41738960
parentc596be08f71e8118ddaa3e330997716de4c109ab (diff)
downloademacs-30c4f35a6fc8a6507930923766c3126ac1c2063f.tar.gz
emacs-30c4f35a6fc8a6507930923766c3126ac1c2063f.zip
query-replace-regexp undo: Update next-replacement after undo
* lisp/replace.el (perform-replace): Rename the local binding to not shadow next-replacement. Update next-replacement after undo (Bug#37287). * test/lisp/replace-tests.el (query-replace-undo-bug37287): Add test. (query-replace-undo-bug37073): Tweak this test.
-rw-r--r--lisp/replace.el14
-rw-r--r--test/lisp/replace-tests.el18
2 files changed, 25 insertions, 7 deletions
diff --git a/lisp/replace.el b/lisp/replace.el
index 0ddebb12704..dd24d8ba923 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -2584,7 +2584,7 @@ It must return a string."
2584 (num-replacements 0) 2584 (num-replacements 0)
2585 (nocasify t) ; Undo must preserve case (Bug#31073). 2585 (nocasify t) ; Undo must preserve case (Bug#31073).
2586 search-string 2586 search-string
2587 next-replacement) 2587 last-replacement)
2588 (while (and (< stack-idx stack-len) 2588 (while (and (< stack-idx stack-len)
2589 stack 2589 stack
2590 (or (null replaced) last-was-act-and-show)) 2590 (or (null replaced) last-was-act-and-show))
@@ -2595,9 +2595,9 @@ It must return a string."
2595 ;; Bind swapped values 2595 ;; Bind swapped values
2596 ;; (search-string <--> replacement) 2596 ;; (search-string <--> replacement)
2597 search-string (nth (if replaced 4 3) elt) 2597 search-string (nth (if replaced 4 3) elt)
2598 next-replacement (nth (if replaced 3 4) elt) 2598 last-replacement (nth (if replaced 3 4) elt)
2599 search-string-replaced search-string 2599 search-string-replaced search-string
2600 next-replacement-replaced next-replacement 2600 last-replacement-replaced last-replacement
2601 last-was-act-and-show nil) 2601 last-was-act-and-show nil)
2602 2602
2603 (when (and (= stack-idx stack-len) 2603 (when (and (= stack-idx stack-len)
@@ -2619,16 +2619,18 @@ It must return a string."
2619 (match-data t (nth 2 elt))) 2619 (match-data t (nth 2 elt)))
2620 noedit 2620 noedit
2621 (replace-match-maybe-edit 2621 (replace-match-maybe-edit
2622 next-replacement nocasify literal 2622 last-replacement nocasify literal
2623 noedit real-match-data backward) 2623 noedit real-match-data backward)
2624 replace-count (1- replace-count) 2624 replace-count (1- replace-count)
2625 real-match-data 2625 real-match-data
2626 (save-excursion 2626 (save-excursion
2627 (goto-char (match-beginning 0)) 2627 (goto-char (match-beginning 0))
2628 (if regexp-flag 2628 (if regexp-flag
2629 (looking-at next-replacement) 2629 (looking-at last-replacement)
2630 (looking-at (regexp-quote next-replacement))) 2630 (looking-at (regexp-quote last-replacement)))
2631 (match-data t (nth 2 elt)))) 2631 (match-data t (nth 2 elt))))
2632 (when regexp-flag
2633 (setq next-replacement (nth 4 elt)))
2632 ;; Set replaced nil to keep in loop 2634 ;; Set replaced nil to keep in loop
2633 (when (eq def 'undo-all) 2635 (when (eq def 'undo-all)
2634 (setq replaced nil 2636 (setq replaced nil
diff --git a/test/lisp/replace-tests.el b/test/lisp/replace-tests.el
index cd08a522e39..2a3f207e47b 100644
--- a/test/lisp/replace-tests.el
+++ b/test/lisp/replace-tests.el
@@ -463,7 +463,9 @@ Return the last evalled form in BODY."
463 (should 463 (should
464 (replace-tests-with-undo 464 (replace-tests-with-undo
465 input "theorem \\([0-9]+\\)" 465 input "theorem \\([0-9]+\\)"
466 "theorem \\\\ref{theo_\\1}" 466 '(replace-eval-replacement
467 replace-quote
468 (format "theorem \\\\ref{theo_%d}" (1+ (string-to-number (match-string 1)))))
467 ((?\s . (1 2)) (?U . (3))) 469 ((?\s . (1 2)) (?U . (3)))
468 ?q 470 ?q
469 (string= input (buffer-string))))) 471 (string= input (buffer-string)))))
@@ -479,4 +481,18 @@ Return the last evalled form in BODY."
479 ?q 481 ?q
480 (string= expected (buffer-string)))))) 482 (string= expected (buffer-string))))))
481 483
484(ert-deftest query-replace-undo-bug37287 ()
485 "Test for https://debbugs.gnu.org/37287 ."
486 (let ((input "foo-1\nfoo-2\nfoo-3")
487 (expected "foo-2\nfoo-2\nfoo-3"))
488 (should
489 (replace-tests-with-undo
490 input "\\([0-9]\\)"
491 '(replace-eval-replacement
492 replace-quote
493 (format "%d" (1+ (string-to-number (match-string 1)))))
494 ((?\s . (1 2 4)) (?U . (3)))
495 ?q
496 (string= expected (buffer-string))))))
497
482;;; replace-tests.el ends here 498;;; replace-tests.el ends here