From: Tino Calancha <tino.calancha@gmail.com>
To: 37073@debbugs.gnu.org
Subject: bug#37073: 26.2.90; query-replace-regexp undo feature missing quote the regexps
Date: Sun, 18 Aug 2019 16:04:00 +0200 [thread overview]
Message-ID: <87h86elgdr.fsf@calancha-pc.dy.bbexcite.jp> (raw)
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@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
next reply other threads:[~2019-08-18 14:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-18 14:04 Tino Calancha [this message]
2019-08-18 21:06 ` bug#37073: 26.2.90; query-replace-regexp undo feature missing quote the regexps Juri Linkov
2019-08-19 15:29 ` Eli Zaretskii
2019-08-19 15:16 ` Tino Calancha
2019-08-19 15:36 ` Tino Calancha
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87h86elgdr.fsf@calancha-pc.dy.bbexcite.jp \
--to=tino.calancha@gmail.com \
--cc=37073@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).