GNU bug report logs -
#37287
26.3.50; query-replace-regexp undo does not update next-replacement
Previous Next
Reported by: Tino Calancha <tino.calancha <at> gmail.com>
Date: Mon, 2 Sep 2019 20:02:02 UTC
Severity: normal
Tags: patch
Found in version 26.3.50
Done: Tino Calancha <tino.calancha <at> gmail.com>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 37287 in the body.
You can then email your comments to 37287 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#37287
; Package
emacs
.
(Mon, 02 Sep 2019 20:02:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Tino Calancha <tino.calancha <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Mon, 02 Sep 2019 20:02:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
emacs -Q
C-x b foo RET
M-: (insert "foo-1\nfoo-2\nfoo-3") RET
M-<
C-M-% \([0-9]\) RET
\,(format "%d" (1+ (string-to-number \1))) RET
SPC
SPC
U
SPC
q
;; buffer contains
"foo-4\nfoo-2\nfoo-3"
;; expected
"foo-2\nfoo-2\nfoo-3"
--8<-----------------------------cut here---------------start------------->8---
commit ff57cbdde0ae9382e043bf335a52ed91ba1b205e
Author: Tino Calancha <tino.calancha <at> gmail.com>
Date: Mon Sep 2 21:58:04 2019 +0200
query-replace-regexp undo: Update next-replacement after undo
* lisp/replace.el (perform-replace):
Use last-replacement for 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.
diff --git a/lisp/replace.el b/lisp/replace.el
index 0ddebb1270..dd24d8ba92 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -2584,7 +2584,7 @@ perform-replace
(num-replacements 0)
(nocasify t) ; Undo must preserve case (Bug#31073).
search-string
- next-replacement)
+ last-replacement)
(while (and (< stack-idx stack-len)
stack
(or (null replaced) last-was-act-and-show))
@@ -2595,9 +2595,9 @@ perform-replace
;; Bind swapped values
;; (search-string <--> replacement)
search-string (nth (if replaced 4 3) elt)
- next-replacement (nth (if replaced 3 4) elt)
+ last-replacement (nth (if replaced 3 4) elt)
search-string-replaced search-string
- next-replacement-replaced next-replacement
+ last-replacement-replaced last-replacement
last-was-act-and-show nil)
(when (and (= stack-idx stack-len)
@@ -2619,16 +2619,18 @@ perform-replace
(match-data t (nth 2 elt)))
noedit
(replace-match-maybe-edit
- next-replacement nocasify literal
+ last-replacement nocasify literal
noedit real-match-data backward)
replace-count (1- replace-count)
real-match-data
(save-excursion
(goto-char (match-beginning 0))
(if regexp-flag
- (looking-at next-replacement)
- (looking-at (regexp-quote next-replacement)))
+ (looking-at last-replacement)
+ (looking-at (regexp-quote last-replacement)))
(match-data t (nth 2 elt))))
+ (when regexp-flag
+ (setq next-replacement (nth 4 elt)))
;; Set replaced nil to keep in loop
(when (eq def 'undo-all)
(setq replaced nil
diff --git a/test/lisp/replace-tests.el b/test/lisp/replace-tests.el
index cd08a522e3..2a3f207e47 100644
--- a/test/lisp/replace-tests.el
+++ b/test/lisp/replace-tests.el
@@ -463,7 +463,9 @@ replace-tests--query-replace-undo
(should
(replace-tests-with-undo
input "theorem \\([0-9]+\\)"
- "theorem \\\\ref{theo_\\1}"
+ '(replace-eval-replacement
+ replace-quote
+ (format "theorem \\\\ref{theo_%d}" (1+ (string-to-number (match-string 1)))))
((?\s . (1 2)) (?U . (3)))
?q
(string= input (buffer-string)))))
@@ -479,4 +481,18 @@ replace-tests--query-replace-undo
?q
(string= expected (buffer-string))))))
+(ert-deftest query-replace-undo-bug37287 ()
+ "Test for https://debbugs.gnu.org/37287 ."
+ (let ((input "foo-1\nfoo-2\nfoo-3")
+ (expected "foo-2\nfoo-2\nfoo-3"))
+ (should
+ (replace-tests-with-undo
+ input "\\([0-9]\\)"
+ '(replace-eval-replacement
+ replace-quote
+ (format "%d" (1+ (string-to-number (match-string 1)))))
+ ((?\s . (1 2 4)) (?U . (3)))
+ ?q
+ (string= expected (buffer-string))))))
+
;;; replace-tests.el ends here
--8<-----------------------------cut here---------------end--------------->8---
In GNU Emacs 26.3.50 (build 4, x86_64-pc-linux-gnu, GTK+ Version 3.24.5)
of 2019-09-02 built on calancha-pc.dy.bbexcite.jp
Repository revision: 7e527af72cae65fdb3f61c7d92907cfdfd1e6ea3
Windowing system distributor 'The X.Org Foundation', version 11.0.12004000
System Description: Debian GNU/Linux 10 (buster)
Added tag(s) patch.
Request was from
Tino Calancha <tino.calancha <at> gmail.com>
to
control <at> debbugs.gnu.org
.
(Mon, 02 Sep 2019 20:04:02 GMT)
Full text and
rfc822 format available.
Reply sent
to
Tino Calancha <tino.calancha <at> gmail.com>
:
You have taken responsibility.
(Mon, 09 Sep 2019 06:27:01 GMT)
Full text and
rfc822 format available.
Notification sent
to
Tino Calancha <tino.calancha <at> gmail.com>
:
bug acknowledged by developer.
(Mon, 09 Sep 2019 06:27:01 GMT)
Full text and
rfc822 format available.
Message #12 received at 37287-done <at> debbugs.gnu.org (full text, mbox):
> emacs -Q
> C-x b foo RET
> M-: (insert "foo-1\nfoo-2\nfoo-3") RET
> M-<
> C-M-% \([0-9]\) RET
> \,(format "%d" (1+ (string-to-number \1))) RET
> SPC
> SPC
> U
> SPC
> q
>
> ;; buffer contains
> "foo-4\nfoo-2\nfoo-3"
> ;; expected
> "foo-2\nfoo-2\nfoo-3"
Fixed in emacs-26 branch with commit
'query-replace-regexp undo: Update next-replacement after undo'
(30c4f35a6fc8a6507930923766c3126ac1c2063f)
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Mon, 07 Oct 2019 11:24:05 GMT)
Full text and
rfc822 format available.
This bug report was last modified 5 years and 173 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.