* bug#8161: 24.0.50; query-replace-regexp fails with interactive replacement text
@ 2011-03-03 8:59 Suvayu Ali
2011-03-03 16:21 ` Lawrence Mitchell
0 siblings, 1 reply; 4+ messages in thread
From: Suvayu Ali @ 2011-03-03 8:59 UTC (permalink / raw
To: 8161
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.
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#8161: 24.0.50; query-replace-regexp fails with interactive replacement text
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
2011-03-03 23:04 ` Juri Linkov
0 siblings, 1 reply; 4+ messages in thread
From: Lawrence Mitchell @ 2011-03-03 16:21 UTC (permalink / raw
To: bug-gnu-emacs
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>
^ permalink raw reply related [flat|nested] 4+ messages in thread
* bug#8161: 24.0.50; query-replace-regexp fails with interactive replacement text
2011-03-03 16:21 ` Lawrence Mitchell
@ 2011-03-03 23:04 ` Juri Linkov
2012-08-05 13:31 ` Chong Yidong
0 siblings, 1 reply; 4+ messages in thread
From: Juri Linkov @ 2011-03-03 23:04 UTC (permalink / raw
To: Lawrence Mitchell; +Cc: 8161
> 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.
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'.
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#8161: 24.0.50; query-replace-regexp fails with interactive replacement text
2011-03-03 23:04 ` Juri Linkov
@ 2012-08-05 13:31 ` Chong Yidong
0 siblings, 0 replies; 4+ messages in thread
From: Chong Yidong @ 2012-08-05 13:31 UTC (permalink / raw
To: Juri Linkov; +Cc: 8161, Lawrence Mitchell
Juri Linkov <juri@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.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-08-05 13:31 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2011-03-03 23:04 ` Juri Linkov
2012-08-05 13:31 ` Chong Yidong
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.