Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

query-replace-regexp interactive replacement string

14 views
Skip to first unread message

suvayu ali

unread,
Mar 2, 2011, 5:52:33 PM3/2/11
to Emacs mailing list
Hi Emacs users,

I wanted to replace interactively all numbers in the text of an org-mode
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("\\?" t nil #("2" 0 1 (fontified t)) nil)
> match-substitute-replacement("\\?" t 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)
> recursive-edit()
> 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:

> ...
> In TO-STRING, ...
> `\?' lets you edit the replacement text in the minibuffer
> at the given position for each replacement.
> ...

I am not sure what I did wrong. I am using GNU Emacs 24.0.50.1
(x86_64-unknown-linux-gnu, GTK+ Version 2.22.0)

Thanks for any thoughts.

--
Suvayu

Open source is the future. It sets us free.

Deniz Dogan

unread,
Mar 3, 2011, 3:03:38 AM3/3/11
to suvayu ali, Emacs mailing list
2011/3/2 suvayu ali <fatkasuv...@gmail.com>:

Weird, it doesn't work for me either. However, if I use
M-x replace-regexp it does work. In "(emacs) Regexp Replace" it also
mentions \?.

"If you want to enter part of the replacement string by hand each
time, use `\?' in the replacement string. Each replacement will ask
you to edit the replacement string in the minibuffer, putting point
where the `\?' was."

--
Deniz Dogan

Suvayu Ali

unread,
Mar 3, 2011, 3:11:37 AM3/3/11
to Deniz Dogan, Emacs mailing list
On Thu, 3 Mar 2011 09:03:38 +0100
Deniz Dogan <deniz.a...@gmail.com> wrote:

> 2011/3/2 suvayu ali <fatkasuv...@gmail.com>:
> > Hi Emacs users,
> >
> > I wanted to replace interactively all numbers in the text of an
> > org-mode document with the number in words, so I tried:
> >
> > `C-M-% [0-9]+ RET \? RET'
> >
> > But this gives me an error like this:

> > ...


> >
>
> Weird, it doesn't work for me either. However, if I use
> M-x replace-regexp it does work. In "(emacs) Regexp Replace" it also
> mentions \?.
>

Thank you for looking into this, I can also confirm that it works for me
with replace-regexp but not query-replace-regexp.

Could it be a bug?

Andreas Röhler

unread,
Mar 3, 2011, 3:39:15 AM3/3/11
to help-gn...@gnu.org

Hi,

can confirm this with

GNU Emacs 23.2.94.1 (i686-pc-linux-gnu, GTK+ Version 2.18.6) of 2011-02-25

Seems worth a bug-report

Thanks


Andreas

--
https://code.launchpad.net/~a-roehler/python-mode/python-mode-components
https://code.launchpad.net/s-x-emacs-werkstatt/


Deniz Dogan

unread,
Mar 3, 2011, 3:35:23 AM3/3/11
to Suvayu Ali, Emacs mailing list
2011/3/3 Suvayu Ali <fatkasuv...@gmail.com>:

> On Thu, 3 Mar 2011 09:03:38 +0100
> Deniz Dogan <deniz.a...@gmail.com> wrote:
>
>> 2011/3/2 suvayu ali <fatkasuv...@gmail.com>:
>> > Hi Emacs users,
>> >
>> > I wanted to replace interactively all numbers in the text of an
>> > org-mode document with the number in words, so I tried:
>> >
>> > `C-M-% [0-9]+ RET \? RET'
>> >
>> > But this gives me an error like this:
>> > ...
>> >
>>
>> Weird, it doesn't work for me either. However, if I use
>> M-x replace-regexp it does work. In "(emacs) Regexp Replace" it also
>> mentions \?.
>>
>
> Thank you for looking into this, I can also confirm that it works for me
> with replace-regexp but not query-replace-regexp.
>
> Could it be a bug?
>

I'm by no means an expert on the subject, I didn't even know about the
"\?" feature, but now we're two people confused by the documentation
vs. the behavior. If it's not a functionality bug, it's a
documentation bug. Please file a report.

Thanks,
Deniz Dogan

Suvayu Ali

unread,
Mar 3, 2011, 4:14:41 AM3/3/11
to Emacs mailing list
Hi Deniz and Andreas,

I have filed a bug report,

http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8161

Thanks,

0 new messages