all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* multiple search strings in query-replace-regexp
@ 2006-10-06 11:17 Florian Kaufmann
  2006-10-06 11:27 ` Malte Spiess
                   ` (2 more replies)
  0 siblings, 3 replies; 26+ messages in thread
From: Florian Kaufmann @ 2006-10-06 11:17 UTC (permalink / raw)


Hello

Is there a way to search/replace for multiple search/replace regexes at
once? I prefer to search for all of them at once instead of serially
because then I can mentally stay at the same context of the file. Lets
say the variables found are mostly found in 5 functions of a source
file. If I do the search serially, I come 5 times across function foo,
and I have to think about what foo does 5 times (so I don't make any
mistakes during search-replace). If I could do all searches at once, I
would only come one time across foo. 

Greetings

Flo

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: multiple search strings in query-replace-regexp
  2006-10-06 11:17 multiple search strings in query-replace-regexp Florian Kaufmann
@ 2006-10-06 11:27 ` Malte Spiess
  2006-10-06 11:41   ` Florian Kaufmann
  2006-10-06 12:41 ` Peter Dyballa
       [not found] ` <mailman.7806.1160138473.9609.help-gnu-emacs@gnu.org>
  2 siblings, 1 reply; 26+ messages in thread
From: Malte Spiess @ 2006-10-06 11:27 UTC (permalink / raw)


"Florian Kaufmann" <sensorflo@gmail.com> writes:

> Hello
>
> Is there a way to search/replace for multiple search/replace regexes at
> once? [...]

How about using \(foo1\|foo2\) ?

> Greetings
>
> Flo

HTH

Malte

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: multiple search strings in query-replace-regexp
  2006-10-06 11:27 ` Malte Spiess
@ 2006-10-06 11:41   ` Florian Kaufmann
  2006-10-06 11:51     ` David Kastrup
  0 siblings, 1 reply; 26+ messages in thread
From: Florian Kaufmann @ 2006-10-06 11:41 UTC (permalink / raw)


that works only for multiple searches at once, but not for multiple
search-replace at once.

replace all foo by bar
replace all rock by house
replace all metal by goa

:-) and so on

Greetings 

Flo

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: multiple search strings in query-replace-regexp
  2006-10-06 11:41   ` Florian Kaufmann
@ 2006-10-06 11:51     ` David Kastrup
  2006-10-06 21:45       ` Ilya Zakharevich
  2006-10-07  8:20       ` Malte Spiess
  0 siblings, 2 replies; 26+ messages in thread
From: David Kastrup @ 2006-10-06 11:51 UTC (permalink / raw)


"Florian Kaufmann" <sensorflo@gmail.com> writes:

> that works only for multiple searches at once, but not for multiple
> search-replace at once.
>
> replace all foo by bar
> replace all rock by house
> replace all metal by goa
>
> :-) and so on

With Emacs 22:

C-M-% \(foo\)\|\(rock\)\|metal RET
\,(cond (\1 "bar") (\2 "house") ("goa")) RET

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: multiple search strings in query-replace-regexp
  2006-10-06 11:17 multiple search strings in query-replace-regexp Florian Kaufmann
  2006-10-06 11:27 ` Malte Spiess
@ 2006-10-06 12:41 ` Peter Dyballa
       [not found] ` <mailman.7806.1160138473.9609.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 26+ messages in thread
From: Peter Dyballa @ 2006-10-06 12:41 UTC (permalink / raw)
  Cc: help-gnu-emacs


Am 06.10.2006 um 13:17 schrieb Florian Kaufmann:

> Is there a way to search/replace for multiple search/replace  
> regexes at
> once?

Write a little function in *scratch* buffer with n replace-regexp,  
then load and apply it!

--
Mit friedvollen Grüßen

   Pete

How many Microsoft engineers does it take to screw in a lightbulb?
None.
They just redefine "dark" as the new standard.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: multiple search strings in query-replace-regexp
       [not found] ` <mailman.7806.1160138473.9609.help-gnu-emacs@gnu.org>
@ 2006-10-06 14:14   ` Florian Kaufmann
  2006-10-06 15:14     ` David Kastrup
  0 siblings, 1 reply; 26+ messages in thread
From: Florian Kaufmann @ 2006-10-06 14:14 UTC (permalink / raw)



> Write a little function in *scratch* buffer with n replace-regexp,
> then load and apply it!

Yes, that's true. But I have to be careful that I take the nearest
match. Something like

saved_point = point
next_match_pos = INFINIT
for all regexes in regexlist {
  match_pos = search( current regex )
  if ( match_pos < next_match_pos ) {
    next_match_pos = match_pos
    regex_to_apply = current regex
  }
  goto saved_point
}
searc_replace( regex_to_apply )

Mhh, no, that doesn't work either. Now how should I implement the thing
that I can press all that query-replace keys like y n . etc? Of course
pressing y should advance to the nearest next match of any of the regex
from the regexlist.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: multiple search strings in query-replace-regexp
  2006-10-06 14:14   ` Florian Kaufmann
@ 2006-10-06 15:14     ` David Kastrup
  2006-10-06 15:29       ` Florian Kaufmann
  0 siblings, 1 reply; 26+ messages in thread
From: David Kastrup @ 2006-10-06 15:14 UTC (permalink / raw)


"Florian Kaufmann" <sensorflo@gmail.com> writes:

> Mhh, no, that doesn't work either. Now how should I implement the
> thing that I can press all that query-replace keys like y n . etc?
> Of course pressing y should advance to the nearest next match of any
> of the regex from the regexlist.

You read the solution I posted?

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: multiple search strings in query-replace-regexp
  2006-10-06 15:14     ` David Kastrup
@ 2006-10-06 15:29       ` Florian Kaufmann
  2006-10-06 15:47         ` David Kastrup
  0 siblings, 1 reply; 26+ messages in thread
From: Florian Kaufmann @ 2006-10-06 15:29 UTC (permalink / raw)



> You read the solution I posted?

Yes. I have XEmacs 21.4 compiled for Windows, and it didn't worked for
me. But thank you for your suggestion anyway

Greetings

Flo

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: multiple search strings in query-replace-regexp
  2006-10-06 15:29       ` Florian Kaufmann
@ 2006-10-06 15:47         ` David Kastrup
  0 siblings, 0 replies; 26+ messages in thread
From: David Kastrup @ 2006-10-06 15:47 UTC (permalink / raw)


"Florian Kaufmann" <sensorflo@gmail.com> writes:

>> You read the solution I posted?
>
> Yes. I have XEmacs 21.4 compiled for Windows, and it didn't worked for
> me.

XEmacs 21.4 compiled for Windows will work for pretty few people
nowadays that utf-8 is commonplace...

> But thank you for your suggestion anyway

If you are asking on "gnu.emacs.help" you should mention it if you are
using XEmacs.  comp.emacs.xemacs _does_ exist.

For Windows users, current developer versions of Emacs 22 are worth
checking out.  There are several precompiled versions of it around.

The robustness of XEmacs 21.5 on Windows presumably is less, but it is
pretty much the only XEmacs on Windows that is supposed to deal
tolerably with utf-8.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: multiple search strings in query-replace-regexp
  2006-10-06 11:51     ` David Kastrup
@ 2006-10-06 21:45       ` Ilya Zakharevich
  2006-10-06 22:01         ` David Kastrup
  2006-10-07  8:20       ` Malte Spiess
  1 sibling, 1 reply; 26+ messages in thread
From: Ilya Zakharevich @ 2006-10-06 21:45 UTC (permalink / raw)


[A complimentary Cc of this posting was sent to
David Kastrup 
<dak@gnu.org>], who wrote in article <85y7rt1x2k.fsf@lola.goethe.zz>:
> With Emacs 22:
> 
> C-M-% \(foo\)\|\(rock\)\|metal RET
> \,(cond (\1 "bar") (\2 "house") ("goa")) RET

To make it useful, one needs a function to count the number of
parentheses in a given regular expression.  Is there?

Yours,
Ilya

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: multiple search strings in query-replace-regexp
  2006-10-06 21:45       ` Ilya Zakharevich
@ 2006-10-06 22:01         ` David Kastrup
  2006-10-07  3:45           ` Ilya Zakharevich
       [not found]           ` <200610070345.k973jLj2011358@powdermilk.math.berkeley.edu>
  0 siblings, 2 replies; 26+ messages in thread
From: David Kastrup @ 2006-10-06 22:01 UTC (permalink / raw)


Ilya Zakharevich <nospam-abuse@ilyaz.org> writes:

> [A complimentary Cc of this posting]

Please don't.  It is sufficient to answer to the list.

> David Kastrup wrote:
>> With Emacs 22:
>> 
>> C-M-% \(foo\)\|\(rock\)\|metal RET
>> \,(cond (\1 "bar") (\2 "house") ("goa")) RET
>
> To make it useful, one needs a function to count the number of
> parentheses in a given regular expression.  Is there?

Uh WHAT?  You just type the above stuff.  Why would that not be
useful?

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: multiple search strings in query-replace-regexp
  2006-10-06 22:01         ` David Kastrup
@ 2006-10-07  3:45           ` Ilya Zakharevich
       [not found]           ` <200610070345.k973jLj2011358@powdermilk.math.berkeley.edu>
  1 sibling, 0 replies; 26+ messages in thread
From: Ilya Zakharevich @ 2006-10-07  3:45 UTC (permalink / raw)


[A complimentary Cc of this posting was sent to
David Kastrup 
<dak@gnu.org>], who wrote in article <85ejtlyuhv.fsf@lola.goethe.zz>:
> >> C-M-% \(foo\)\|\(rock\)\|metal RET
> >> \,(cond (\1 "bar") (\2 "house") ("goa")) RET
> >
> > To make it useful, one needs a function to count the number of
> > parentheses in a given regular expression.  Is there?

> Uh WHAT?  You just type the above stuff.  Why would that not be
> useful?

How many people do you know who would type something like this?  :-(

And to have a "generally usable" wrapper, one needs a way to identify
how many paren groups are inside your "foo" and "rock" regular
expressions.

Hope this helps,
Ilya

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: multiple search strings in query-replace-regexp
       [not found]           ` <200610070345.k973jLj2011358@powdermilk.math.berkeley.edu>
@ 2006-10-07  7:41             ` David Kastrup
  2006-10-07  8:57               ` Ilya Zakharevich
  0 siblings, 1 reply; 26+ messages in thread
From: David Kastrup @ 2006-10-07  7:41 UTC (permalink / raw)


Ilya Zakharevich <nospam-abuse@ilyaz.org> writes:

> [A complimentary Cc of this posting was sent to
> David Kastrup 
> <dak@gnu.org>],

I already told you to leave off "complimentary copies" to group
articles: they are a breach of netiquette since they add no valuable
information at all and tend to confuse the recipient into having to
reply multiple times: once in mail, and later, when the mistake has
been noticed, on the group again.

Please stop this nuisance.  You can expect that people writing on
Usenet groups are also reading there.

> who wrote in article <85ejtlyuhv.fsf@lola.goethe.zz>:
>> >> C-M-% \(foo\)\|\(rock\)\|metal RET
>> >> \,(cond (\1 "bar") (\2 "house") ("goa")) RET
>> >
>> > To make it useful, one needs a function to count the number of
>> > parentheses in a given regular expression.  Is there?
>
>> Uh WHAT?  You just type the above stuff.  Why would that not be
>> useful?
>
> How many people do you know who would type something like this?  :-(

Well, enough for the idiom to be useful.  That's why it was invented
and documented.

> And to have a "generally usable" wrapper, one needs a way to
> identify how many paren groups are inside your "foo" and "rock"
> regular expressions.

I can't actually think of a user interface for such a wrapper that
would not really complicate things.  In particular if you want to
refer to matched groups in the replacements, it is pretty hard to come
up with anything close to a useful interface.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: multiple search strings in query-replace-regexp
  2006-10-06 11:51     ` David Kastrup
  2006-10-06 21:45       ` Ilya Zakharevich
@ 2006-10-07  8:20       ` Malte Spiess
  2006-10-07  8:40         ` David Kastrup
  1 sibling, 1 reply; 26+ messages in thread
From: Malte Spiess @ 2006-10-07  8:20 UTC (permalink / raw)


David Kastrup <dak@gnu.org> writes:

> "Florian Kaufmann" <sensorflo@gmail.com> writes:
>
>> that works only for multiple searches at once, but not for multiple
>> search-replace at once.
>>
>> replace all foo by bar
>> replace all rock by house
>> replace all metal by goa
>>
>> :-) and so on
>
> With Emacs 22:
>
> C-M-% \(foo\)\|\(rock\)\|metal RET
> \,(cond (\1 "bar") (\2 "house") ("goa")) RET

Doesn't work with Emacs 21.4.1 :-(...

Looks pretty impressive though!
Does \, cause to execute lisp stuff?

Btw: Shouldn't

C-M-% \(foo\|rock\)\|metal RET
\,(cond (\1 "bar") (\1 "house") ("goa")) RET

work, too?

Greetings

Malte

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: multiple search strings in query-replace-regexp
  2006-10-07  8:20       ` Malte Spiess
@ 2006-10-07  8:40         ` David Kastrup
  0 siblings, 0 replies; 26+ messages in thread
From: David Kastrup @ 2006-10-07  8:40 UTC (permalink / raw)


Malte Spiess <i1tnews@arcor.de> writes:

> David Kastrup <dak@gnu.org> writes:
>
>> "Florian Kaufmann" <sensorflo@gmail.com> writes:
>>
>>> that works only for multiple searches at once, but not for multiple
>>> search-replace at once.
>>>
>>> replace all foo by bar
>>> replace all rock by house
>>> replace all metal by goa
>>>
>>> :-) and so on
>>
>> With Emacs 22:
>>
>> C-M-% \(foo\)\|\(rock\)\|metal RET
>> \,(cond (\1 "bar") (\2 "house") ("goa")) RET
>
> Doesn't work with Emacs 21.4.1 :-(...

Emacs 22 is about to enter pretest (I'd guess within a week), so there
is little reason not to join the testers if one would like the
features.

> Looks pretty impressive though!
> Does \, cause to execute lisp stuff?

Yes.  The doc string spells this out, but the manual is a bit more
verbose:

   The remainder of this subsection is intended for specialized tasks
and requires knowledge of Lisp.  Most readers can skip it.

   You can use Lisp expressions to calculate parts of the replacement
string.  To do this, write `\,' followed by the expression in the
replacement string.  Each replacement calculates the value of the
expression and converts it to text without quoting (if it's a string,
this means using the string's contents), and uses it in the replacement
string in place of the expression itself.  If the expression is a
symbol, one space in the replacement string after the symbol name goes
with the symbol name, so the value replaces them both.

   Inside such an expression, you can use some special sequences.  `\&'
and `\N' refer here, as usual, to the entire match as a string, and to
a submatch as a string.  N may be multiple digits, and the value of
`\N' is `nil' if subexpression N did not match.  You can also use `\#&'
and `\#N' to refer to those matches as numbers (this is valid when the
match or submatch has the form of a numeral).  `\#' here too stands for
the number of already-completed replacements.

   Repeating our example to exchange `x' and `y', we can thus do it
also this way:

     M-x replace-regexp <RET> \(x\)\|y <RET>
     \,(if \1 "y" "x") <RET>

   For computing replacement strings for `\,', the `format' function is
often useful (*note Formatting Strings: (elisp)Formatting Strings.).
For example, to add consecutively numbered strings like `ABC00042' to
columns 73 to 80 (unless they are already occupied), you can use

     M-x replace-regexp <RET> ^.\{0,72\}$ <RET>
     \,(format "%-72sABC%05d" \& \#) <RET>


> Btw: Shouldn't
>
> C-M-% \(foo\|rock\)\|metal RET
> \,(cond (\1 "bar") (\1 "house") ("goa")) RET
>
> work, too?

No.  It would replace either "foo" or "rock" with "bar", and "metal"
with "goa".

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: multiple search strings in query-replace-regexp
  2006-10-07  7:41             ` David Kastrup
@ 2006-10-07  8:57               ` Ilya Zakharevich
  2006-10-07  9:11                 ` David Kastrup
  0 siblings, 1 reply; 26+ messages in thread
From: Ilya Zakharevich @ 2006-10-07  8:57 UTC (permalink / raw)


[A complimentary Cc of this posting was NOT [per weedlist] sent to
David Kastrup 
<dak@gnu.org>], who wrote in article <85iriwy3m0.fsf@lola.goethe.zz>:
> > [A complimentary Cc of this posting was NOT [per weedlist] sent to
> > David Kastrup 
> > <dak@gnu.org>],
> 
> I already told you to leave off "complimentary copies" to group
> articles: they are a breach of netiquette since they add no valuable
> information at all and tend to confuse the recipient into having to
> reply multiple times: once in mail, and later, when the mistake has
> been noticed, on the group again.

Fill free to read this header again.  Thanks.

BTW, you know that sending BLIND Cc is considered a breach of
netiquette, right, and you know the reasons?  And still you do it...
Sigh...

> Please stop this nuisance.  You can expect that people writing on
> Usenet groups are also reading there.

Your statement would have some significance if Usenet were a reliable
media.  It was not 20 years ago.  It still is not.

> >> >> C-M-% \(foo\)\|\(rock\)\|metal RET
> >> >> \,(cond (\1 "bar") (\2 "house") ("goa")) RET
> >> >
> >> > To make it useful, one needs a function to count the number of
> >> > parentheses in a given regular expression.  Is there?
> >
> >> Uh WHAT?  You just type the above stuff.  Why would that not be
> >> useful?
> >
> > How many people do you know who would type something like this?  :-(

> Well, enough for the idiom to be useful.  That's why it was invented
> and documented.

Enough to invent and document it.  AFAIK, not enough for it to be useful.

> > And to have a "generally usable" wrapper, one needs a way to
> > identify how many paren groups are inside your "foo" and "rock"
> > regular expressions.
> 
> I can't actually think of a user interface for such a wrapper that
> would not really complicate things.  In particular if you want to
> refer to matched groups in the replacements, it is pretty hard to come
> up with anything close to a useful interface.

All this means is that you had a bad day.  Just revisit it in a day or
so, if you do not know the answer already.  [Hint at the end of the
message. ;-]

Yours,
Ilya























































Hint: one presses ENTER to end the replacement string.  What about
pressing something els, like C-u ENTER?  ;-)

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: multiple search strings in query-replace-regexp
  2006-10-07  8:57               ` Ilya Zakharevich
@ 2006-10-07  9:11                 ` David Kastrup
  2006-10-07 22:04                   ` Ilya Zakharevich
  0 siblings, 1 reply; 26+ messages in thread
From: David Kastrup @ 2006-10-07  9:11 UTC (permalink / raw)


Ilya Zakharevich <nospam-abuse@ilyaz.org> writes:

> [A complimentary Cc of this posting was NOT [per weedlist] sent to
> David Kastrup 
> <dak@gnu.org>], who wrote in article <85iriwy3m0.fsf@lola.goethe.zz>:
>> > [A complimentary Cc of this posting was NOT [per weedlist] sent to
>> > David Kastrup 
>> > <dak@gnu.org>],
>> 
>> I already told you to leave off "complimentary copies" to group
>> articles: they are a breach of netiquette since they add no valuable
>> information at all and tend to confuse the recipient into having to
>> reply multiple times: once in mail, and later, when the mistake has
>> been noticed, on the group again.
>
> Fill free to read this header again.  Thanks.
>
> BTW, you know that sending BLIND Cc is considered a breach of
> netiquette, right, and you know the reasons?  And still you do it...
> Sigh...

That was not a blind CC.  That was a separate mail sent first, before
I noticed.  It was the reply to your mail.  I had to repost this reply
to the list when I noticed.

You should have noticed the difference: the group version carried the
complaint, the mail version didn't.

So you are, in effect, complaining that your "courtesy copy" had just
the bad effect I told you it had.

>> Please stop this nuisance.  You can expect that people writing on
>> Usenet groups are also reading there.
>
> Your statement would have some significance if Usenet were a
> reliable media.  It was not 20 years ago.  It still is not.

But your message contained no information that would have been
personally important to me.  So there was no point in making sure that
it specifically reached me in case Usenet failed.

>> >> >> C-M-% \(foo\)\|\(rock\)\|metal RET
>> >> >> \,(cond (\1 "bar") (\2 "house") ("goa")) RET
>> >> >
>> >> > To make it useful, one needs a function to count the number of
>> >> > parentheses in a given regular expression.  Is there?
>> >
>> >> Uh WHAT?  You just type the above stuff.  Why would that not be
>> >> useful?
>> >
>> > How many people do you know who would type something like this?  :-(
>
>> Well, enough for the idiom to be useful.  That's why it was invented
>> and documented.
>
> Enough to invent and document it.  AFAIK, not enough for it to be
> useful.

Well, if it is not useful, there is no point in complaining about it.
Just don't use it, then.

>> > And to have a "generally usable" wrapper, one needs a way to
>> > identify how many paren groups are inside your "foo" and "rock"
>> > regular expressions.
>> 
>> I can't actually think of a user interface for such a wrapper that
>> would not really complicate things.  In particular if you want to
>> refer to matched groups in the replacements, it is pretty hard to
>> come up with anything close to a useful interface.
>
> All this means is that you had a bad day.  Just revisit it in a day
> or so, if you do not know the answer already.  [Hint at the end of
> the message. ;-]

> Hint: one presses ENTER to end the replacement string.  What about
> pressing something els, like C-u ENTER?  ;-)

How about rereading what I wrote above?  "In particular if you want to
refer to matched groups in the replacements, it is pretty hard to come
up with anything close to a useful interface."

So how does C-u RET make it easy to refer to matched groups?

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: multiple search strings in query-replace-regexp
  2006-10-07  9:11                 ` David Kastrup
@ 2006-10-07 22:04                   ` Ilya Zakharevich
  2006-10-08 13:47                     ` Mathias Dahl
  2006-10-09  6:07                     ` Stefan Monnier
  0 siblings, 2 replies; 26+ messages in thread
From: Ilya Zakharevich @ 2006-10-07 22:04 UTC (permalink / raw)


[A complimentary Cc of this posting was NOT [per weedlist] sent to
David Kastrup 
<dak@gnu.org>], who wrote in article <85wt7cwkwc.fsf@lola.goethe.zz>:

  [META: the following line is correct.]

> > [A complimentary Cc of this posting was NOT [per weedlist] sent to
> > David Kastrup 
> > <dak@gnu.org>], who wrote in article <85iriwy3m0.fsf@lola.goethe.zz>:

  [META: the following line is a lie]

> >> > [A complimentary Cc of this posting was NOT [per weedlist] sent to
> >> > David Kastrup 
> >> > <dak@gnu.org>],

Sigh; my mangler edited not only the header, but also the body of the
message.  Initially, I did not notice this, and built my reply to you
based on wrong assumption.

So sorry, I do not know why your name was not in weed list - assuming
you asked me before...

> So you are, in effect, complaining that your "courtesy copy" had just
> the bad effect I told you it had.

Correct.  My apologies.

> But your message contained no information that would have been
> personally important to me.

Maybe; but such is hard to predict when posting.

> Well, if it is not useful, there is no point in complaining about it.

Did I?

> > Hint: one presses ENTER to end the replacement string.  What about
> > pressing something els, like C-u ENTER?  ;-)
> 
> How about rereading what I wrote above?  "In particular if you want to
> refer to matched groups in the replacements, it is pretty hard to come
> up with anything close to a useful interface."

> So how does C-u RET make it easy to refer to matched groups?

How about rereading what I wrote above?  "To make it useful, one needs
a function to count the number of parentheses in a given regular
expression.  Is there?"

Given this, C-M-% (or whatever is the key in default Emacs bindings)
could just accept multiple pairs REGEXP + REPLACEMENT (separated,
e.g., by C-u RET).

Hope this helps,
Ilya

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: multiple search strings in query-replace-regexp
  2006-10-07 22:04                   ` Ilya Zakharevich
@ 2006-10-08 13:47                     ` Mathias Dahl
  2006-10-08 20:55                       ` Kim F. Storm
       [not found]                       ` <mailman.7905.1160340972.9609.help-gnu-emacs@gnu.org>
  2006-10-09  6:07                     ` Stefan Monnier
  1 sibling, 2 replies; 26+ messages in thread
From: Mathias Dahl @ 2006-10-08 13:47 UTC (permalink / raw)


Ilya Zakharevich <nospam-abuse@ilyaz.org> writes:

> Given this, C-M-% (or whatever is the key in default Emacs bindings)
> could just accept multiple pairs REGEXP + REPLACEMENT (separated,
> e.g., by C-u RET).

Hmm, I think that could work quite nicely. C-RET could also be an
option. Would probably need quite some changes to the code though;
currently I guess `query-replace-regexp' uses `read-string' or similar
and I am not sure how it would react to C-u RET.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: multiple search strings in query-replace-regexp
  2006-10-08 13:47                     ` Mathias Dahl
@ 2006-10-08 20:55                       ` Kim F. Storm
       [not found]                       ` <mailman.7905.1160340972.9609.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 26+ messages in thread
From: Kim F. Storm @ 2006-10-08 20:55 UTC (permalink / raw)
  Cc: help-gnu-emacs

Mathias Dahl <brakjoller@gmail.com> writes:

> Ilya Zakharevich <nospam-abuse@ilyaz.org> writes:
>
>> Given this, C-M-% (or whatever is the key in default Emacs bindings)
>> could just accept multiple pairs REGEXP + REPLACEMENT (separated,
>> e.g., by C-u RET).
>
> Hmm, I think that could work quite nicely. C-RET could also be an

C-RET is used by CUA-mode to mark a rectangle.

> option. Would probably need quite some changes to the code though;
> currently I guess `query-replace-regexp' uses `read-string' or similar
> and I am not sure how it would react to C-u RET.

-- 
Kim F. Storm  http://www.cua.dk

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: multiple search strings in query-replace-regexp
  2006-10-07 22:04                   ` Ilya Zakharevich
  2006-10-08 13:47                     ` Mathias Dahl
@ 2006-10-09  6:07                     ` Stefan Monnier
  2006-10-09 21:53                       ` Ilya Zakharevich
  1 sibling, 1 reply; 26+ messages in thread
From: Stefan Monnier @ 2006-10-09  6:07 UTC (permalink / raw)


> How about rereading what I wrote above?  "To make it useful, one needs
> a function to count the number of parentheses in a given regular
> expression.  Is there?"

`regexp-opt-depth' claims to do that.  I believe the version in Emacs-CVS is
pretty reliable.


        Stefan

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: multiple search strings in query-replace-regexp
  2006-10-09  6:07                     ` Stefan Monnier
@ 2006-10-09 21:53                       ` Ilya Zakharevich
  2006-10-09 22:21                         ` David Kastrup
  2006-11-23 19:23                         ` Stefan Monnier
  0 siblings, 2 replies; 26+ messages in thread
From: Ilya Zakharevich @ 2006-10-09 21:53 UTC (permalink / raw)


[A complimentary Cc of this posting was sent to
Stefan Monnier 
<monnier@iro.umontreal.ca>], who wrote in article <jwvu02epwqf.fsf-monnier+gnu.emacs.help@gnu.org>:
> > How about rereading what I wrote above?  "To make it useful, one needs
> > a function to count the number of parentheses in a given regular
> > expression.  Is there?"
> 
> `regexp-opt-depth' claims to do that.  I believe the version in Emacs-CVS is
> pretty reliable.

Thanks; still, when combining several regexps into one, one needs to
fixup backreferences.  Given the horrible ELisp regexp syntax, this
requires some dirty backwacking...  E.g., I'm not sure I would be able
to do it right first time (hint: the newer CPerl facification of
RegExps would do it very easy with Perl regexps; much harder to do it
with ELisp...).

Hmm, I see that at least in Elist v19, backreferences went only up to
9; sigh...  Well, this is not needed very often, one could just

 (error
  "RegExp limitation hit, try to make pattern(s) with backreferences first")

or some such.

-------

Additionally, when interpolating replacement string, one should also
shift match-group references by corresponding amount; but this is
easier done in the code of interpolator (I hope it is in ELisp, not in
C).

Yours,
Ilya

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: multiple search strings in query-replace-regexp
  2006-10-09 21:53                       ` Ilya Zakharevich
@ 2006-10-09 22:21                         ` David Kastrup
  2006-10-10  3:39                           ` Ilya Zakharevich
  2006-11-23 19:23                         ` Stefan Monnier
  1 sibling, 1 reply; 26+ messages in thread
From: David Kastrup @ 2006-10-09 22:21 UTC (permalink / raw)


Ilya Zakharevich <nospam-abuse@ilyaz.org> writes:

> [A complimentary Cc of this posting was sent to
> Stefan Monnier 
> <monnier@iro.umontreal.ca>], who wrote in article <jwvu02epwqf.fsf-monnier+gnu.emacs.help@gnu.org>:
>> > How about rereading what I wrote above?  "To make it useful, one needs
>> > a function to count the number of parentheses in a given regular
>> > expression.  Is there?"
>> 
>> `regexp-opt-depth' claims to do that.  I believe the version in Emacs-CVS is
>> pretty reliable.
>
> Thanks; still, when combining several regexps into one, one needs to
> fixup backreferences.  Given the horrible ELisp regexp syntax, this
> requires some dirty backwacking...  E.g., I'm not sure I would be able
> to do it right first time (hint: the newer CPerl facification of
> RegExps would do it very easy with Perl regexps; much harder to do it
> with ELisp...).
>
> Hmm, I see that at least in Elist v19, backreferences went only up to
> 9; sigh...  Well, this is not needed very often, one could just
>
>  (error
>   "RegExp limitation hit, try to make pattern(s) with backreferences first")
>
> or some such.
>
> -------
>
> Additionally, when interpolating replacement string, one should also
> shift match-group references by corresponding amount; but this is
> easier done in the code of interpolator (I hope it is in ELisp, not in
> C).

Your quoting does not make it clear who wrote what.  Anyway, you could
just use match-data, nthcdr, set-match-data and some other stuff to
just shift the match data appropriately before performing the
replacement.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: multiple search strings in query-replace-regexp
  2006-10-09 22:21                         ` David Kastrup
@ 2006-10-10  3:39                           ` Ilya Zakharevich
  0 siblings, 0 replies; 26+ messages in thread
From: Ilya Zakharevich @ 2006-10-10  3:39 UTC (permalink / raw)


[A complimentary Cc of this posting was NOT [per weedlist] sent to
David Kastrup 
<dak@gnu.org>], who wrote in article <85zmc5xh9f.fsf@lola.goethe.zz>:
> > Additionally, when interpolating replacement string, one should also
> > shift match-group references by corresponding amount; but this is
> > easier done in the code of interpolator (I hope it is in ELisp, not in
> > C).

> Your quoting does not make it clear who wrote what.  Anyway, you could
> just use match-data, nthcdr, set-match-data and some other stuff to
> just shift the match data appropriately before performing the
> replacement.

Neet idea.

Yours,
Ilya

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: multiple search strings in query-replace-regexp
       [not found]                       ` <mailman.7905.1160340972.9609.help-gnu-emacs@gnu.org>
@ 2006-10-12 15:44                         ` Mathias Dahl
  0 siblings, 0 replies; 26+ messages in thread
From: Mathias Dahl @ 2006-10-12 15:44 UTC (permalink / raw)


no-spam@cua.dk (Kim F. Storm) writes:

>> Hmm, I think that could work quite nicely. C-RET could also be an
>
> C-RET is used by CUA-mode to mark a rectangle.

But this would be a binding on the prompt (read-string or whatever).

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: multiple search strings in query-replace-regexp
  2006-10-09 21:53                       ` Ilya Zakharevich
  2006-10-09 22:21                         ` David Kastrup
@ 2006-11-23 19:23                         ` Stefan Monnier
  1 sibling, 0 replies; 26+ messages in thread
From: Stefan Monnier @ 2006-11-23 19:23 UTC (permalink / raw)


> Thanks; still, when combining several regexps into one, one needs to
> fixup backreferences.

Yup.  I actually have a local patch which fixes that by providing relative
backrefs (e.g. \-1 refers to the last group and \-2 to the one before that).


        Stefan

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2006-11-23 19:23 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-06 11:17 multiple search strings in query-replace-regexp Florian Kaufmann
2006-10-06 11:27 ` Malte Spiess
2006-10-06 11:41   ` Florian Kaufmann
2006-10-06 11:51     ` David Kastrup
2006-10-06 21:45       ` Ilya Zakharevich
2006-10-06 22:01         ` David Kastrup
2006-10-07  3:45           ` Ilya Zakharevich
     [not found]           ` <200610070345.k973jLj2011358@powdermilk.math.berkeley.edu>
2006-10-07  7:41             ` David Kastrup
2006-10-07  8:57               ` Ilya Zakharevich
2006-10-07  9:11                 ` David Kastrup
2006-10-07 22:04                   ` Ilya Zakharevich
2006-10-08 13:47                     ` Mathias Dahl
2006-10-08 20:55                       ` Kim F. Storm
     [not found]                       ` <mailman.7905.1160340972.9609.help-gnu-emacs@gnu.org>
2006-10-12 15:44                         ` Mathias Dahl
2006-10-09  6:07                     ` Stefan Monnier
2006-10-09 21:53                       ` Ilya Zakharevich
2006-10-09 22:21                         ` David Kastrup
2006-10-10  3:39                           ` Ilya Zakharevich
2006-11-23 19:23                         ` Stefan Monnier
2006-10-07  8:20       ` Malte Spiess
2006-10-07  8:40         ` David Kastrup
2006-10-06 12:41 ` Peter Dyballa
     [not found] ` <mailman.7806.1160138473.9609.help-gnu-emacs@gnu.org>
2006-10-06 14:14   ` Florian Kaufmann
2006-10-06 15:14     ` David Kastrup
2006-10-06 15:29       ` Florian Kaufmann
2006-10-06 15:47         ` David Kastrup

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.