Subject: 24.0.50; query-replace-regexp fails with interactive replacement text

From: Suvayu Ali <[email-masked]>
Date: Thu, 3 Mar 2011 00:59:37 -0800

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:

> ...
> In TO-STRING, `\&' stands for whatever matched the whole of REGEXP,
> and `\N' (where N is a digit) stands for
> whatever what matched the Nth `\(...\)' in REGEXP.
> `\?' lets you edit the replacement text in the minibuffer
> at the given position for each replacement.
> ...

and two other users have confirmed[1] this behaviour on the
help-gnu-emacs list, I believe this is a bug. I have included all the
information below starting emacs with "emacs -Q".

Hope this helps tracking down the bug.

Suvayu

[1]http://groups.google.com/group/gnu.emacs.help/browse_thread/thread/8f5ef5f9ade589e3#

In GNU Emacs 24.0.50.1 (x86_64-unknown-linux-gnu, GTK+ Version 2.20.1)
 of 2011-03-02 on bhishma.homelinux.net
Windowing system distributor `Fedora Project', version 11.0.10802000
configured using `configure  '--prefix=/opt/emacs-lisp'
'--with-selinux' '--with-imagemagick''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: en_IN.utf8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix
  default enable-multibyte-characters: t

Major mode: Debugger

Minor modes in effect:
  tooltip-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
1 <return> 2 <return> 3 <return> 4 <return> <return> 
5 <up> <delete> <down> <down> <return> 6 <return> 7 
<return> 8 <return> 9 <return> 0 <return> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<down> <down> <help-echo> <help-echo> <help-echo> <help-echo> 
<help-echo> <help-echo> <help-echo> <help-echo> <help-echo> 
<help-echo> <help-echo> <help-echo> <help-echo> <help-echo> 
<help-echo> <help-echo> <help-echo> <help-echo> <help-echo> 
<help-echo> <help-echo> <help-echo> <help-echo> <help-echo> 
<help-echo> <help-echo> <help-echo> <help-echo> <menu-bar> 
<options> <debug-on-error> C-M-% [ 0 - 9 ] + <return> 
\ ? <return> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> C-SPC <down> <down> <down> <down> <down> 
<down> <down> M-w M-x e m a c s - r e p o <tab> <backspace> 
<backspace> <backspace> <backspace> <backspace> <backspace> 
<backspace> <backspace> <backspace> <backspace> r e 
p o <tab> t <tab> <backspace> r t <tab> - <tab> <backspace> 
<tab> <return>

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
byte-code: End of buffer [2 times]
Debug on Error enabled globally
Mark set
Entering debugger...
byte-code: Beginning of buffer [4 times]
Mark set
byte-code: End of buffer
Making completion list...

Load-path shadows:
/opt/emacs-lisp/share/emacs/site-lisp/flim/hex-util
hides /opt/emacs-lisp/share/emacs/24.0.50/lisp/hex-util /opt/emacs-lisp/share/emacs/site-lisp/flim/sha1
hides /opt/emacs-lisp/share/emacs/24.0.50/lisp/sha1 /opt/emacs-lisp/share/emacs/site-lisp/flim/md4
hides /opt/emacs-lisp/share/emacs/24.0.50/lisp/md4 /opt/emacs-lisp/share/emacs/site-lisp/flim/ntlm
hides /opt/emacs-lisp/share/emacs/24.0.50/lisp/net/ntlm /opt/emacs-lisp/share/emacs/site-lisp/flim/sasl
hides /opt/emacs-lisp/share/emacs/24.0.50/lisp/net/sasl /opt/emacs-lisp/share/emacs/site-lisp/flim/sasl-digest
hides /opt/emacs-lisp/share/emacs/24.0.50/lisp/net/sasl-digest /opt/emacs-lisp/share/emacs/site-lisp/flim/sasl-cram
hides /opt/emacs-lisp/share/emacs/24.0.50/lisp/net/sasl-cram /opt/emacs-lisp/share/emacs/site-lisp/flim/sasl-ntlm
hides /opt/emacs-lisp/share/emacs/24.0.50/lisp/net/sasl-ntlm /opt/emacs-lisp/share/emacs/site-lisp/flim/hmac-md5
hides /opt/emacs-lisp/share/emacs/24.0.50/lisp/net/hmac-md5 /opt/emacs-lisp/share/emacs/site-lisp/flim/hmac-def
hides /opt/emacs-lisp/share/emacs/24.0.50/lisp/net/hmac-def

Features:
(shadow sort mail-extr message idna sendmail regexp-opt rfc822 mml
mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231 rfc2047 rfc2045
ietf-drums mailabbrev mail-utils gmm-utils mailheader emacsbug url-util
url-parse auth-source eieio byte-opt bytecomp byte-compile assoc
gnus-util time-date password-cache url-vars mm-util mail-prsvr help-mode
easymenu view debug cus-start cus-load tooltip ediff-hook vc-hooks
lisp-float-type mwheel x-win x-dnd tool-bar dnd fontset image fringe
lisp-mode register page menu-bar rfn-eshadow timer select scroll-bar
mouse jit-lock font-lock syntax facemenu font-core frame cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese case-table epa-hook jka-cmpr-hook help simple abbrev
loaddefs button minibuffer faces cus-face files text-properties overlay
md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote make-network-process dbusbind
dynamic-setting system-font-setting font-render-setting move-toolbar gtk
x-toolkit x multi-tty emacs)

-- 
Suvayu

Open source is the future. It sets us free.