]> git.eshelyaron.com Git - emacs.git/commitdiff
Preserve case in query-replace undo
authorTino Calancha <tino.calancha@gmail.com>
Mon, 9 Apr 2018 02:47:47 +0000 (11:47 +0900)
committerTino Calancha <tino.calancha@gmail.com>
Mon, 9 Apr 2018 02:47:47 +0000 (11:47 +0900)
If the user query and replaces 'foo' with 'BAR', then
undo must comeback to 'foo', not to 'FOO' (Bug#31073).
* lisp/replace.el (perform-replace): Bind nocasify to non-nil
value during undo/undo-all actions.
* test/lisp/replace-tests.el (query-replace-undo-bug31073): Add test.

lisp/replace.el
test/lisp/replace-tests.el

index c28c9b36f055cd77c48da5b945fe9ad8e9b99ae1..4916cb138e619f6432118e12316a2e59140a8415 100644 (file)
@@ -2619,6 +2619,7 @@ It must return a string."
                           (let ((stack-idx         0)
                                  (stack-len         (length stack))
                                  (num-replacements  0)
+                                 (nocasify t) ; Undo must preserve case (Bug#31073).
                                  search-string
                                  next-replacement)
                              (while (and (< stack-idx stack-len)
index 66c6842660774e20de9c6cdfd15c6f9b1bb7b8e3..40a1a31cf7c2670279da84271f93b8b42e1eaa8e 100644 (file)
@@ -380,4 +380,24 @@ Each element has the format:
   (should (string= "211" (replace-tests--query-replace-undo)))
   (should (string= "211" (replace-tests--query-replace-undo 'comma))))
 
+(ert-deftest query-replace-undo-bug31073 ()
+  "Test for https://debbugs.gnu.org/31073 ."
+  (let ((text "aaa aaa")
+        (count 0))
+    (with-temp-buffer
+      (insert text)
+      (goto-char 1)
+      (cl-letf (((symbol-function 'read-event)
+                 (lambda (&rest args)
+                   (cl-incf count)
+                   (let ((val (pcase count
+                                ((or 1 2 3) ?\s) ; replace current and go next
+                                (4 ?U) ; undo-all
+                                (_ ?q)))) ; exit
+                     val))))
+        (perform-replace "a" "B" t nil nil))
+      ;; After undo text must be the same.
+      (should (string= text (buffer-string))))))
+
+
 ;;; replace-tests.el ends here