GNU bug report logs - #31492
26.1; query-replace-regexp undo fails in regexps w/o printable chars

Previous Next

Package: emacs;

Reported by: Tino Calancha <tino.calancha <at> gmail.com>

Date: Fri, 18 May 2018 13:28:02 UTC

Severity: normal

Found in version 26.1

Done: Tino Calancha <tino.calancha <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Tino Calancha <tino.calancha <at> gmail.com>
Subject: bug#31492: closed (Re: bug#31492: 26.1; query-replace-regexp undo
 fails in regexps w/o printable chars)
Date: Wed, 23 May 2018 09:24:04 +0000
[Message part 1 (text/plain, inline)]
Your bug report

#31492: 26.1; query-replace-regexp undo fails in regexps w/o printable chars

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 31492 <at> debbugs.gnu.org.

-- 
31492: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=31492
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Tino Calancha <tino.calancha <at> gmail.com>
To: 31492-done <at> debbugs.gnu.org
Subject: Re: bug#31492: 26.1;
 query-replace-regexp undo fails in regexps w/o printable chars
Date: Wed, 23 May 2018 18:22:57 +0900
Eli Zaretskii <eliz <at> gnu.org> writes:

>> From: Tino Calancha <tino.calancha <at> gmail.com>
>> Cc: 31492 <at> debbugs.gnu.org
>> Date: Mon, 21 May 2018 10:51:43 +0900
>> Following patch is equivalent to the 2nd and its 1-liner
>> (excluded clarification comments):
>
> Thanks, LGTM.  If no comments emerge in a couple of days, please push.
Pushed into master branch as 'Fix corner case in query-replace-regexp
undo'
(bab73230d1be1fe394b7269c1365ef6fb1a5d9b3)

[Message part 3 (message/rfc822, inline)]
From: Tino Calancha <tino.calancha <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 26.1; query-replace-regexp undo fails in regexps w/o printable chars
Date: Fri, 18 May 2018 22:27:36 +0900
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 <at> 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



This bug report was last modified 7 years and 4 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.