GNU bug report logs -
#37073
26.2.90; query-replace-regexp undo feature missing quote the regexps
Previous Next
Reported by: Tino Calancha <tino.calancha <at> gmail.com>
Date: Sun, 18 Aug 2019 14:05:01 UTC
Severity: normal
Tags: patch
Found in version 26.2.90
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
[Message part 1 (text/plain, inline)]
Your bug report
#37073: 26.2.90; query-replace-regexp undo feature missing quote the regexps
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 37073 <at> debbugs.gnu.org.
--
37073: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=37073
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
>> This looks good, but please ask Eli about pushing it to emacs-26 branch.
>I'm okay with pushing this to emacs-26, but please do it soon, because
>RC1 of 26.3 is in the works.
Pushed into emacs-26 as commit 'Fix query-replace-regexp undo feature'
(beb1d22260af2e03d80d34fcc1db212785a9d903)
[Hopefully soon enough :-|]
[Message part 3 (message/rfc822, inline)]
Tags: patch
That causes the undo feature to fail if the replacement contains special characters.
emacs -Q
C-x b *foo* RET
M-: (insert "theorem 1\ntheorem 2\ntheorem 3") RET
M-<
M-C-%
theorem \([0-9]+\) RET
\,(format "theorem \\ref{theo_%s}" \1) RET
SPC
SPC
u
q
;; Buffer *foo* now contains:
theorem 1ref{theo_1}
theorem 2ref{theo_2}
theorem 3
;; Expected:
theorem 1
theorem 2
theorem 3
--8<-----------------------------cut here---------------start------------->8---
commit 9f9c56cfa99b1e6fe296ec591ab335521e185e55
Author: Tino Calancha <tino.calancha <at> gmail.com>
Date: Sun Aug 18 15:57:59 2019 +0200
Fix query-replace-regexp undo feature
* lisp/replace.el (perform-replace): Quote regexp (Bug#37073).
* test/lisp/replace-tests.el (query-replace-undo-bug37073): Add test
diff --git a/lisp/replace.el b/lisp/replace.el
index 08feb8eae7..fb703abd92 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -2614,7 +2614,7 @@ perform-replace
(setq real-match-data
(save-excursion
(goto-char (match-beginning 0))
- (looking-at search-string)
+ (looking-at (regexp-quote search-string)) ; Bug#37073
(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 cd30633e37..f96bd9cf05 100644
--- a/test/lisp/replace-tests.el
+++ b/test/lisp/replace-tests.el
@@ -454,5 +454,15 @@ replace-tests--query-replace-undo
input "a" "B" ((?\s . (1 2 3)) (?E . (4)) (?U . (5))) ?q
(string= input (buffer-string))))))
+(ert-deftest query-replace-undo-bug37073 ()
+ "Test for https://debbugs.gnu.org/37073 ."
+ (let ((input "theorem 1\ntheorem 2\ntheorem 3"))
+ (should
+ (replace-tests-with-undo
+ input "theorem \\([0-9]+\\)"
+ "theorem \\\\ref{theo_\\1}"
+ ((?\s . (1 2)) (?U . (3)))
+ ?q
+ (string= input (buffer-string))))))
;;; replace-tests.el ends here
--8<-----------------------------cut here---------------end--------------->8---
In GNU Emacs 26.2.90 (build 19, x86_64-pc-linux-gnu, GTK+ Version 3.24.5)
of 2019-08-18 built
Repository revision: 3f00db7ca6d40312651a302842561e7fb168ee99
This bug report was last modified 5 years and 272 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.