From: Lawrence Mitchell <wence@gmx.li>
To: bug-gnu-emacs@gnu.org
Subject: bug#8161: 24.0.50; query-replace-regexp fails with interactive replacement text
Date: Thu, 03 Mar 2011 16:21:47 +0000 [thread overview]
Message-ID: <m3pqq8dvj8.fsf@e4300lm.epcc.ed.ac.uk> (raw)
In-Reply-To: <20110303005937.1804abf6@bhishma.homelinux.net>
Suvayu Ali wrote:
> Hi Emacs devs,
> I wanted to replace interactively all numbers in the text of an document
> with the number in words, so I tried:
> `C-M-% [0-9]+ RET \? RET'
> But this gives me an error like this:
>> Debugger entered--Lisp error: (error "Invalid use of `\\' in
>> replacement text") replace-match("\\?" nil nil #("1" 0 1 (fontified
>> t)) nil) match-substitute-replacement("\\?" nil nil)
>> perform-replace("[0-9]+" "\\?" t t nil nil nil nil nil)
>> query-replace-regexp("[0-9]+" "\\?" nil nil nil)
>> call-interactively(query-replace-regexp nil nil)
> Since the doc string of `query-replace-regexp' says the following:
This has been broken since
Author: Juri Linkov <juri@jurta.org>
Date: Sat Nov 10 21:48:46 2007 +0000
(query-replace-show-replacement): New defcustom.
(perform-replace): Use `match-substitute-replacement' if
`query-replace-show-replacement' is non-nil.
replace-match (used by match-substitute-replacement) doesn't know
about \? and therefore barfs.
This patch just passes \\? unchanged through replace-match. I'm
not sure if this is a reasonable fix, although minimal testing
suggests it all works correctly.
diff --git a/src/search.c b/src/search.c
index 1e2036f..c9fd71b 100644
--- a/src/search.c
+++ b/src/search.c
@@ -2373,6 +2373,7 @@ Otherwise treat `\\' as special:
`\\N' means substitute what matched the Nth `\\(...\\)'.
If Nth parens didn't match, substitute nothing.
`\\\\' means insert one `\\'.
+ `\\?' (as in `query-replace-regexp') is passed through unchanged.
Case conversion does not apply to these substitutions.
FIXEDCASE and LITERAL are optional arguments.
@@ -2575,6 +2576,8 @@ since only regular expressions have distinguished subexpressions. */)
}
else if (c == '\\')
delbackslash = 1;
+ else if (c == '?')
+ ; /* do nothing (dealt with at lisp level) */
else
error ("Invalid use of `\\' in replacement text");
}
Lawrence
--
Lawrence Mitchell <wence@gmx.li>
next prev parent reply other threads:[~2011-03-03 16:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-03 8:59 bug#8161: 24.0.50; query-replace-regexp fails with interactive replacement text Suvayu Ali
2011-03-03 16:21 ` Lawrence Mitchell [this message]
2011-03-03 23:04 ` Juri Linkov
2012-08-05 13:31 ` Chong Yidong
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m3pqq8dvj8.fsf@e4300lm.epcc.ed.ac.uk \
--to=wence@gmx.li \
--cc=bug-gnu-emacs@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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.