unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
Cc: emacs-devel@gnu.org
Subject: Re: query-replace-interactive
Date: Mon, 05 Jul 2004 09:08:46 +0300	[thread overview]
Message-ID: <87k6xjouj5.fsf@mail.jurta.org> (raw)
In-Reply-To: <m1u0wn22cj.fsf-monnier+emacs@gnu.org> (Stefan's message of "04 Jul 2004 12:13:36 -0400")

Stefan <monnier@iro.umontreal.ca> writes:
>> But the last search string still could be used as the `default'
>> argument of `read-from-minibuffer'.  This is not quite a "default"
>> value but rather what the Emacs manual names as "future history" value,
>> i.e. the value available with M-n.
>
> I think we've already agreed that M-% should offer
>
>    Query replace (default foo -> bar): 
>
> i.e. default to redo the same replace as last time, rather than use the
> last search string.

Even if using the last replacement as default doesn't hurt, such use
of the default value is non-standard in Emacs.  Usually, the default
value is available for inserting into the minibuffer by typing M-n,
but not in this case, since inserting "foo -> bar" into the minibuffer
is useless.  Moreover, the last replacement actually consists of the
last elements of the replacement history.  The standard Emacs way to
access the history values is M-p.  But this is not possible for two
separate replacement values (from and to) either.

One possibility to follow Emacs conventions is to use a user-defined
value `query-replace-args-separator' to allow to specify both
from-string and to-string in the same input string.  In this case
there is no need in interpreting an empty input string as repeating
the last replacement since the last replacement (as well as all
previous replacements) are easily accessible by M-p.  However, I am
not sure this option should have some non-nil value by default.

But even in case with the default to repeat the last replacement it is
possible to use the last search string/regexp as a default value only
for the sake of making it available by M-n.  But the real default value
(such as used when the user types RET with empty input) could be
interpreted as repeating the last replacement, since if the user
enters empty input, `read-from-minibuffer' returns the empty string,
not the argument `default-value'.

>> I implemented it having in mind users' requests for the ability to
>> copy words from the buffer into the from-string.  Now this is possible
>> by typing:
>
>> C-s C-w C-w ... M-%
>
> C-SPC M-f M-f ... M-w M-% C-y

Yes, currently this is the most convenient method to do that but it
requires more keystrokes and wastes the kill ring.

There are other cases where making the last search string accessible
by M-n is useful.  For example, users might want to start replacing
the current search string from the beginning of the buffer.  To not
type C-r several times to reach the beginning of the buffer the user
can type:

C-s C-w C-w ... RET M-< M-% M-n RET

So, in conclusion, I agree that M-% in isearch should not ask for
the from-string with initial content of the last search string,
but M-% invoked not from isearch could provide the last search string
by M-n.

>>> (perform-replace isearch-string nil t isearch-regexp isearch-word) instead.
>>                                   ===
>> If the argument `replacements' is nil, this function signals an error.
>> Moreover, it's impossible to guess the to-string, so asking for it from
>> the user is still inevitable.
>
> Oh, right, I forgot that part of my local hacks
> [...]
> Obviously, it's not good enough.  But we can easily take out the "read
> `to'" part of query-replace-read-args.

Calling `perform-replace' directly is not good because it skips many
useful things implemented in interactive commands which call it.
Most useful of them is recently added handling of \, and \# in
`query-replace-read-args'.

> The point about using perform-replace is that it allows us to obey
> both isearch-regexp and isearch-word without doing any if-gymnastic.

Using `isearch-regexp' to call either `query-replace' or
`query-replace-regexp' is easy.  Using the value of `isearch-word' for
replacement might be tricky but currently this is possible with the
prefix argument C-u M-% or C-u C-M-% even in isearch.

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

  reply	other threads:[~2004-07-05  6:08 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-03 22:59 query-replace-interactive Stefan
2004-07-04  9:54 ` query-replace-interactive Juri Linkov
2004-07-04 16:13   ` query-replace-interactive Stefan
2004-07-05  6:08     ` Juri Linkov [this message]
2004-07-05 12:44       ` query-replace-interactive Stefan
2004-07-06  9:56         ` query-replace-interactive Juri Linkov
2004-07-06 22:00           ` query-replace-interactive Richard Stallman
2004-07-07  5:11             ` query-replace-interactive Juri Linkov
2004-07-07  5:42               ` query-replace-interactive Miles Bader
2004-07-07  9:35               ` query-replace-interactive David Kastrup
2004-07-07 20:58               ` query-replace-interactive Richard Stallman
2004-07-06 22:00           ` query-replace-interactive Richard Stallman
2004-07-06 22:11             ` query-replace-interactive David Kastrup
2004-07-06 11:53       ` query-replace-interactive Richard Stallman
2004-07-06 12:24         ` query-replace-interactive Stefan
2004-07-07  6:41           ` query-replace-interactive Richard Stallman
2004-07-06 11:53       ` query-replace-interactive Richard Stallman
2004-07-06 12:09         ` query-replace-interactive David Kastrup
2004-07-07  6:41           ` query-replace-interactive Richard Stallman
  -- strict thread matches above, loose matches on Subject: below --
2004-10-11  1:10 query-replace-interactive Luc Teirlinck
2004-10-11  1:18 ` query-replace-interactive Luc Teirlinck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k6xjouj5.fsf@mail.jurta.org \
    --to=juri@jurta.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).