GNU bug report logs - #8161
24.0.50; query-replace-regexp fails with interactive replacement text

Previous Next

Package: emacs;

Reported by: Suvayu Ali <fatkasuvayu+linux <at> gmail.com>

Date: Thu, 3 Mar 2011 09:00:03 UTC

Severity: normal

Found in version 24.0.50

Done: Chong Yidong <cyd <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 8161 in the body.
You can then email your comments to 8161 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#8161; Package emacs. (Thu, 03 Mar 2011 09:00:04 GMT) Full text and rfc822 format available.

Acknowledgement sent to Suvayu Ali <fatkasuvayu+linux <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 03 Mar 2011 09:00:04 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Suvayu Ali <fatkasuvayu+linux <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.0.50; query-replace-regexp fails with interactive replacement text
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.




Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#8161; Package emacs. (Thu, 03 Mar 2011 16:23:02 GMT) Full text and rfc822 format available.

Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Lawrence Mitchell <wence <at> gmx.li>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#8161: 24.0.50;
	query-replace-regexp fails with interactive replacement text
Date: Thu, 03 Mar 2011 16:21:47 +0000
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 <at> 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 <at> gmx.li>





Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#8161; Package emacs. (Thu, 03 Mar 2011 23:09:02 GMT) Full text and rfc822 format available.

Message #11 received at 8161 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: Lawrence Mitchell <wence <at> gmx.li>
Cc: 8161 <at> debbugs.gnu.org
Subject: Re: bug#8161: 24.0.50;
	query-replace-regexp fails with interactive replacement text
Date: Fri, 04 Mar 2011 01:04:46 +0200
> This has been broken since
>
> Author: Juri Linkov <juri <at> 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.

Don't blame the committer ;-)  This feature (\?) is specific to
`query-replace-regexp', so mentioning it in low-level `replace-match'
would be wrong.  It should be dealt at the same level where it's used
in replace.el the same way as \? is processed in `replace-match-maybe-edit'.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#8161; Package emacs. (Sun, 05 Aug 2012 13:40:02 GMT) Full text and rfc822 format available.

Message #14 received at 8161 <at> debbugs.gnu.org (full text, mbox):

From: Chong Yidong <cyd <at> gnu.org>
To: Juri Linkov <juri <at> jurta.org>
Cc: 8161 <at> debbugs.gnu.org, Lawrence Mitchell <wence <at> gmx.li>
Subject: Re: bug#8161: 24.0.50;
	query-replace-regexp fails with interactive replacement text
Date: Sun, 05 Aug 2012 21:31:49 +0800
Juri Linkov <juri <at> jurta.org> writes:

> This feature (\?) is specific to `query-replace-regexp', so mentioning
> it in low-level `replace-match' would be wrong.  It should be dealt at
> the same level where it's used in replace.el the same way as \? is
> processed in `replace-match-maybe-edit'.

I didn't see a clean way to do this, so I committed Lawrence's patch.
This bug ought to have been fixed for 24.1, but it got lost in the pile;
sorry.




bug closed, send any further explanations to 8161 <at> debbugs.gnu.org and Suvayu Ali <fatkasuvayu+linux <at> gmail.com> Request was from Chong Yidong <cyd <at> gnu.org> to control <at> debbugs.gnu.org. (Sun, 05 Aug 2012 13:40:03 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 03 Sep 2012 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 11 years and 248 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.