unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#31492: 26.1; query-replace-regexp undo fails in regexps w/o printable chars
@ 2018-05-18 13:27 Tino Calancha
  2018-05-18 14:16 ` Eli Zaretskii
  0 siblings, 1 reply; 17+ messages in thread
From: Tino Calancha @ 2018-05-18 13:27 UTC (permalink / raw)
  To: 31492


emacs -Q

< C-M-% \b RET foo RET TAB TAB TAB
U ; undo all replacements
;; Nothing is undid :-(

--8<-----------------------------cut here---------------start------------->8---
commit f1ee02d0c0bef4534c895559eb53b1ac0ecfb752
Author: Tino Calancha <tino.calancha@gmail.com>
Date:   Fri May 18 22:19:18 2018 +0900

    Fix corner case in query-replace-regexp undo
    
    * lisp/replace.el (perform-replace): Handle the case of a regexp
    not having printable characters (Bug#31492).
    
    * test/lisp/replace-tests.el (query-replace-undo-bug31492): Add test.

diff --git a/lisp/replace.el b/lisp/replace.el
index 3503b656d9..526a40d230 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -2692,7 +2692,9 @@ perform-replace
                                    (setq real-match-data
                                          (save-excursion
                                            (goto-char (match-beginning 0))
-                                           (looking-at search-string)
+                                           (if (/= (match-beginning 0) (match-end 0))
+					       (looking-at search-string)
+					     (looking-back search-string (- (point) (length search-string))))
                                            (match-data t (nth 2 elt)))
                                          noedit
                                          (replace-match-maybe-edit
diff --git a/test/lisp/replace-tests.el b/test/lisp/replace-tests.el
index 40a1a31cf7..5c0ec2aa1c 100644
--- a/test/lisp/replace-tests.el
+++ b/test/lisp/replace-tests.el
@@ -399,5 +399,25 @@ replace-tests--query-replace-undo
       ;; After undo text must be the same.
       (should (string= text (buffer-string))))))
 
+(ert-deftest query-replace-undo-bug31492 ()
+  "Test for https://debbugs.gnu.org/31492 ."
+  (let ((text "a\nb\nc\n")
+        (count 0)
+        (inhibit-message t))
+    (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) ?\s) ; replace current and go next
+                                (3 ?U) ; undo-all
+                                (_ ?q)))) ; exit
+                     val))))
+        (perform-replace "^\\|\b\\|$" "foo" t t nil))
+      ;; After undo text must be the same.
+      (should (string= text (buffer-string))))))
+
 
 ;;; replace-tests.el ends here
--8<-----------------------------cut here---------------end--------------->8---

In GNU Emacs 26.1 (build 6, x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
 of 2018-05-18 built on calancha-pc
Repository revision: 73bc6f8693fcbb98b41ee67ab35a4dd8c3940355





^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2018-05-23  9:22 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-18 13:27 bug#31492: 26.1; query-replace-regexp undo fails in regexps w/o printable chars Tino Calancha
2018-05-18 14:16 ` Eli Zaretskii
2018-05-18 14:22   ` Tino Calancha
2018-05-18 15:07     ` Eli Zaretskii
2018-05-19  1:46       ` Tino Calancha
2018-05-19  7:50         ` Eli Zaretskii
2018-05-19 14:28           ` Tino Calancha
2018-05-20  9:29             ` Eli Zaretskii
2018-05-20 11:51               ` Tino Calancha
2018-05-20 11:59                 ` Eli Zaretskii
2018-05-20 12:06                   ` Tino Calancha
2018-05-20 12:48                     ` Eli Zaretskii
2018-05-20 13:46                       ` Tino Calancha
2018-05-20 15:47                         ` Eli Zaretskii
2018-05-21  1:51                           ` Tino Calancha
2018-05-21 15:05                             ` Eli Zaretskii
2018-05-23  9:22                               ` Tino Calancha

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).