unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* replace history
@ 2007-12-26 23:20 Reuben Thomas
  2007-12-26 23:48 ` Dan Nicolaescu
  2007-12-27 20:11 ` Juri Linkov
  0 siblings, 2 replies; 16+ messages in thread
From: Reuben Thomas @ 2007-12-26 23:20 UTC (permalink / raw)
  To: Emacs Bugs

In Emacs 22 it's great the way that you are given the last search/replace 
pair as a default for query-replace, but is there a way to get a history of 
pairs rather than alternating search item/replace item?

-- 
http://rrt.sc3d.org/ | The shorter the better




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

* Re: replace history
  2007-12-26 23:20 replace history Reuben Thomas
@ 2007-12-26 23:48 ` Dan Nicolaescu
  2007-12-27 11:42   ` Bastien
  2007-12-27 20:12   ` Juri Linkov
  2007-12-27 20:11 ` Juri Linkov
  1 sibling, 2 replies; 16+ messages in thread
From: Dan Nicolaescu @ 2007-12-26 23:48 UTC (permalink / raw)
  To: Reuben Thomas; +Cc: Emacs Bugs

Reuben Thomas <rrt@sc3d.org> writes:

  > In Emacs 22 it's great the way that you are given the last
  > search/replace pair as a default for query-replace, but is there a way
  > to get a history of pairs rather than alternating search item/replace
  > item?

There isn't. I would also love to have such a feature. Bound for example
to C-M-p and C-M-n




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

* Re: replace history
  2007-12-26 23:48 ` Dan Nicolaescu
@ 2007-12-27 11:42   ` Bastien
  2007-12-27 20:14     ` Juri Linkov
  2007-12-27 20:12   ` Juri Linkov
  1 sibling, 1 reply; 16+ messages in thread
From: Bastien @ 2007-12-27 11:42 UTC (permalink / raw)
  To: Dan Nicolaescu; +Cc: Emacs Bugs, Reuben Thomas

Dan Nicolaescu <dann@ics.uci.edu> writes:

> Reuben Thomas <rrt@sc3d.org> writes:
>
>   > In Emacs 22 it's great the way that you are given the last
>   > search/replace pair as a default for query-replace, but is there a way
>   > to get a history of pairs rather than alternating search item/replace
>   > item?
>
> There isn't. I would also love to have such a feature. Bound for example
> to C-M-p and C-M-n

FWIW I would also love this feature.

Another idea: make `C-u M-x query-replace' *reverse* the default pair.
This would be useful to undo a replacement.

-- 
Bastien




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

* Re: replace history
  2007-12-26 23:20 replace history Reuben Thomas
  2007-12-26 23:48 ` Dan Nicolaescu
@ 2007-12-27 20:11 ` Juri Linkov
  2007-12-28 13:55   ` Richard Stallman
  1 sibling, 1 reply; 16+ messages in thread
From: Juri Linkov @ 2007-12-27 20:11 UTC (permalink / raw)
  To: Reuben Thomas; +Cc: Emacs Bugs

> In Emacs 22 it's great the way that you are given the last search/replace
> pair as a default for query-replace, but is there a way to get a history
> of pairs rather than alternating search item/replace item?

One way to implement this feature is to use one input string with the
ed-like syntax "s/regex/substitution/g".

Below is the simplest function that implements this.  It reads such
a string from the minibuffer (with the query-replace history list and
a convenient default input string), parses it and calls perform-replace
with proper arguments querying for each replacement when the input string
contains the "g" flag.

(defun substitute-regexp (substitution)
  (interactive
   (list
    (read-from-minibuffer "Substitute regexp: " '("s///g" . 3) nil nil
                          'query-replace-history nil t)))
  (if (string-match "^s/\\(.*\\)/\\(.*\\)/\\([gi]*\\)" substitution)
      (let* ((regex (match-string 1 substitution))
             (subst (match-string 2 substitution))
             (flags (match-string 3 substitution))
             (case-fold-search (string-match "i" flags)))
        (perform-replace
         regex subst (string-match "g" flags)
         t nil nil nil
         (if (and transient-mark-mode mark-active) (region-beginning))
         (if (and transient-mark-mode mark-active) (region-end))))
    (error "Invalid syntax")))

-- 
Juri Linkov
http://www.jurta.org/emacs/




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

* Re: replace history
  2007-12-26 23:48 ` Dan Nicolaescu
  2007-12-27 11:42   ` Bastien
@ 2007-12-27 20:12   ` Juri Linkov
  2007-12-27 20:40     ` Dan Nicolaescu
                       ` (2 more replies)
  1 sibling, 3 replies; 16+ messages in thread
From: Juri Linkov @ 2007-12-27 20:12 UTC (permalink / raw)
  To: Dan Nicolaescu; +Cc: Emacs Bugs, Reuben Thomas

>   > In Emacs 22 it's great the way that you are given the last
>   > search/replace pair as a default for query-replace, but is there a way
>   > to get a history of pairs rather than alternating search item/replace
>   > item?
>
> There isn't. I would also love to have such a feature. Bound for example
> to C-M-p and C-M-n

How do you imagine it could insert two separate history elements for
from-string and to-string simultaneously?  Maybe, C-M-p typed in the
from-string minibuffer should switch to the to-string reading, and
typing C-M-p in the to-string minibuffer should also change the prompt
that displays the from-string while reading the to-string, e.g.

Query replace: <C-M-p>

Query replace from1 with: to1 <C-M-p>

Query replace from2 with: to2 <C-M-p>

-- 
Juri Linkov
http://www.jurta.org/emacs/




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

* Re: replace history
  2007-12-27 11:42   ` Bastien
@ 2007-12-27 20:14     ` Juri Linkov
  0 siblings, 0 replies; 16+ messages in thread
From: Juri Linkov @ 2007-12-27 20:14 UTC (permalink / raw)
  To: Bastien; +Cc: Emacs Bugs, Dan Nicolaescu, Reuben Thomas

>>   > In Emacs 22 it's great the way that you are given the last
>>   > search/replace pair as a default for query-replace, but is there a way
>>   > to get a history of pairs rather than alternating search item/replace
>>   > item?
>>
>> There isn't. I would also love to have such a feature. Bound for example
>> to C-M-p and C-M-n
>
> FWIW I would also love this feature.
>
> Another idea: make `C-u M-x query-replace' *reverse* the default pair.

The prefix argument of `query-replace' is already assigned to the
delimited meaning to replace matches surrounded by word boundaries.

To reverse the last two query-replace history elements you already can use
`M-% M-p RET M-p M-p M-p RET'.

> This would be useful to undo a replacement.

Isn't the undo command a much easier way to undo the last replacement?

-- 
Juri Linkov
http://www.jurta.org/emacs/




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

* Re: replace history
  2007-12-27 20:12   ` Juri Linkov
@ 2007-12-27 20:40     ` Dan Nicolaescu
  2007-12-28 13:55     ` Richard Stallman
       [not found]     ` <mailman.5457.1198850122.18990.bug-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 16+ messages in thread
From: Dan Nicolaescu @ 2007-12-27 20:40 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Emacs Bugs, Reuben Thomas

Juri Linkov <juri@jurta.org> writes:

  > >   > In Emacs 22 it's great the way that you are given the last
  > >   > search/replace pair as a default for query-replace, but is there a way
  > >   > to get a history of pairs rather than alternating search item/replace
  > >   > item?
  > >
  > > There isn't. I would also love to have such a feature. Bound for example
  > > to C-M-p and C-M-n
  > 
  > How do you imagine it could insert two separate history elements for
  > from-string and to-string simultaneously? 

Similar to what you said. The minibufrer prompt now looks like:


Query replace (default foo -> bar): 

After C-M-p it would change to: 

Query replace (default baz -> foobar): 

so one only need to press C-M-p and RET. 





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

* Re: replace history
  2007-12-27 20:12   ` Juri Linkov
  2007-12-27 20:40     ` Dan Nicolaescu
@ 2007-12-28 13:55     ` Richard Stallman
       [not found]     ` <mailman.5457.1198850122.18990.bug-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 16+ messages in thread
From: Richard Stallman @ 2007-12-28 13:55 UTC (permalink / raw)
  To: Juri Linkov; +Cc: bug-gnu-emacs, dann, rrt

I am somewhat unhappy at the idea of giving a special meaning to C-M-p
in the minibuffer.  It is true that its usual meaning (backward-list)
will not be used often in the minibuffer.  But it will be used
sometimes.




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

* Re: replace history
  2007-12-27 20:11 ` Juri Linkov
@ 2007-12-28 13:55   ` Richard Stallman
  2008-01-03 21:46     ` Juri Linkov
  0 siblings, 1 reply; 16+ messages in thread
From: Richard Stallman @ 2007-12-28 13:55 UTC (permalink / raw)
  To: Juri Linkov; +Cc: bug-gnu-emacs, rrt

    > In Emacs 22 it's great the way that you are given the last search/replace
    > pair as a default for query-replace, but is there a way to get a history
    > of pairs rather than alternating search item/replace item?

    One way to implement this feature is to use one input string with the
    ed-like syntax "s/regex/substitution/g".

I don't think this really does the job.  It is a separate command
that you have to use INSTEAD of query-replace.

What's requested is a way to move thru the history of recent
query-replace argument pairs.




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

* Re: replace history
       [not found]     ` <mailman.5457.1198850122.18990.bug-gnu-emacs@gnu.org>
@ 2008-01-02 13:21       ` Mathias Dahl
  2008-01-03 21:45         ` Juri Linkov
  0 siblings, 1 reply; 16+ messages in thread
From: Mathias Dahl @ 2008-01-02 13:21 UTC (permalink / raw)
  To: gnu-emacs-bug

Richard Stallman <rms@gnu.org> writes:

    I am somewhat unhappy at the idea of giving a special meaning to
    C-M-p in the minibuffer.  It is true that its usual meaning
    (backward-list) will not be used often in the minibuffer.  But it
    will be used sometimes.

I would think that for example in `eval-expression' this would be
true, but do you really think it is needed for `query-replace'?

I think Dan's suggested way of operation would be really neat, but I
don't care much what key that activates this feature. Someone
mentioned using a prefix argument and that it was already taken. How
about differentiate between prefix arguments (negative versus positive
etc), as some commands do?




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

* Re: replace history
  2008-01-02 13:21       ` Mathias Dahl
@ 2008-01-03 21:45         ` Juri Linkov
  2008-01-03 22:15           ` Mathias Dahl
  0 siblings, 1 reply; 16+ messages in thread
From: Juri Linkov @ 2008-01-03 21:45 UTC (permalink / raw)
  To: Mathias Dahl; +Cc: bug-gnu-emacs

> I think Dan's suggested way of operation would be really neat, but I
> don't care much what key that activates this feature. Someone
> mentioned using a prefix argument and that it was already taken. How
> about differentiate between prefix arguments (negative versus positive
> etc), as some commands do?

Such as `C-u -2 M-%' to get the penultimate replacement pair?
This would be not very convenient when you don't remember your
replacement history, so you need to try different prefix arguments
before finding the necessary one.

-- 
Juri Linkov
http://www.jurta.org/emacs/




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

* Re: replace history
  2007-12-28 13:55   ` Richard Stallman
@ 2008-01-03 21:46     ` Juri Linkov
  2008-01-05  5:54       ` Richard Stallman
  0 siblings, 1 reply; 16+ messages in thread
From: Juri Linkov @ 2008-01-03 21:46 UTC (permalink / raw)
  To: rms; +Cc: bug-gnu-emacs, rrt

>     > In Emacs 22 it's great the way that you are given the last search/replace
>     > pair as a default for query-replace, but is there a way to get a history
>     > of pairs rather than alternating search item/replace item?
>
>     One way to implement this feature is to use one input string with the
>     ed-like syntax "s/regex/substitution/g".
>
> I don't think this really does the job.  It is a separate command
> that you have to use INSTEAD of query-replace.
>
> What's requested is a way to move thru the history of recent
> query-replace argument pairs.

One way to move thru the history of recent pairs is to put all pairs to
the default list of M-%.  Every pair needs to be in the same format as
currently used to display the default value in its prompt - with an arrow
separating the FROM and TO arguments like "from1 -> to1".  This has a drawback
that after typing RET with a string in this format, query-replace needs
to parse it, and separately add FROM and TO to the history lists.

-- 
Juri Linkov
http://www.jurta.org/emacs/




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

* Re: replace history
  2008-01-03 21:45         ` Juri Linkov
@ 2008-01-03 22:15           ` Mathias Dahl
  2008-01-03 22:47             ` Juri Linkov
  0 siblings, 1 reply; 16+ messages in thread
From: Mathias Dahl @ 2008-01-03 22:15 UTC (permalink / raw)
  To: Juri Linkov; +Cc: bug-gnu-emacs, Mathias Dahl

> > I think Dan's suggested way of operation would be really neat, but I
> > don't care much what key that activates this feature. Someone
> > mentioned using a prefix argument and that it was already taken. How
> > about differentiate between prefix arguments (negative versus positive
> > etc), as some commands do?
>
> Such as `C-u -2 M-%' to get the penultimate replacement pair?
> This would be not very convenient when you don't remember your
> replacement history, so you need to try different prefix arguments
> before finding the necessary one.

No no, not to select a certain history item. To control the behavior of M-p
and M-n in the command.




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

* Re: replace history
  2008-01-03 22:15           ` Mathias Dahl
@ 2008-01-03 22:47             ` Juri Linkov
  2008-01-03 23:24               ` Mathias Dahl
  0 siblings, 1 reply; 16+ messages in thread
From: Juri Linkov @ 2008-01-03 22:47 UTC (permalink / raw)
  To: Mathias Dahl; +Cc: bug-gnu-emacs, Mathias Dahl

>> > I think Dan's suggested way of operation would be really neat, but I
>> > don't care much what key that activates this feature. Someone
>> > mentioned using a prefix argument and that it was already taken. How
>> > about differentiate between prefix arguments (negative versus positive
>> > etc), as some commands do?
>>
>> Such as `C-u -2 M-%' to get the penultimate replacement pair?
>> This would be not very convenient when you don't remember your
>> replacement history, so you need to try different prefix arguments
>> before finding the necessary one.
>
> No no, not to select a certain history item. To control the behavior of M-p
> and M-n in the command.

Prefix arguments (both positive and negative) of M-p and M-n are too useful
to take them for something else.

-- 
Juri Linkov
http://www.jurta.org/emacs/




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

* Re: replace history
  2008-01-03 22:47             ` Juri Linkov
@ 2008-01-03 23:24               ` Mathias Dahl
  0 siblings, 0 replies; 16+ messages in thread
From: Mathias Dahl @ 2008-01-03 23:24 UTC (permalink / raw)
  To: Juri Linkov; +Cc: bug-gnu-emacs, Mathias Dahl

> > No no, not to select a certain history item. To control the behavior of M-p
> > and M-n in the command.
>
> Prefix arguments (both positive and negative) of M-p and M-n are too useful
> to take them for something else.

It seems I am still being a bit fuzzy :) I mean that a special prefix
argument to
`query-replace' would make M-p and M-n work differently inside `query-replace'.




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

* Re: replace history
  2008-01-03 21:46     ` Juri Linkov
@ 2008-01-05  5:54       ` Richard Stallman
  0 siblings, 0 replies; 16+ messages in thread
From: Richard Stallman @ 2008-01-05  5:54 UTC (permalink / raw)
  To: Juri Linkov; +Cc: bug-gnu-emacs, rrt

    One way to move thru the history of recent pairs is to put all pairs to
    the default list of M-%.

I am not sure what that means.  Do you mean, instead of putting both
args separately in the history list, put a string of the form "FROM ->
TO" in it?

That seems kludgy.  Also, it raises two questions:

1. Does that actually work?

2. Would that make it impossible to do the things you can do now with
the history in query-replace, such as use a previous replacement
target as a pattern to search for?





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

end of thread, other threads:[~2008-01-05  5:54 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-26 23:20 replace history Reuben Thomas
2007-12-26 23:48 ` Dan Nicolaescu
2007-12-27 11:42   ` Bastien
2007-12-27 20:14     ` Juri Linkov
2007-12-27 20:12   ` Juri Linkov
2007-12-27 20:40     ` Dan Nicolaescu
2007-12-28 13:55     ` Richard Stallman
     [not found]     ` <mailman.5457.1198850122.18990.bug-gnu-emacs@gnu.org>
2008-01-02 13:21       ` Mathias Dahl
2008-01-03 21:45         ` Juri Linkov
2008-01-03 22:15           ` Mathias Dahl
2008-01-03 22:47             ` Juri Linkov
2008-01-03 23:24               ` Mathias Dahl
2007-12-27 20:11 ` Juri Linkov
2007-12-28 13:55   ` Richard Stallman
2008-01-03 21:46     ` Juri Linkov
2008-01-05  5:54       ` Richard Stallman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).