Subject: Re: bug#41692: 26.3; Enhancement request, `query-replace': let user use text at point as default

From: Juri Linkov <[email-masked]>
Date: Thu, 04 Jun 2020 01:54:47 +0300

> If you want to default the FROM or TO text for `query-replace' to some
> text at point, you currently need to first isearch for it.  This request
> is essentially to be able to skip doing that.
>
> As an example (only), in my own code, my version of
> `query-replace-read-from' can get the default any of these ways:
>
> * Text of nonempty active region, if option
>   `search/replace-region-as-default-flag' is non-nil.
>
> * Text of secondary selection, if option
>   `search/replace-2nd-sel-as-default-flag' is non-nil.
>
> * What the (function) value of option `search/replace-default-fn'
>   returns, when called.  This defaults to a function that grabs text at
>   point.  (If the function returns a list of strings, then those are the
>   multiple default values.)
>
> (As with vanilla query-replace, you can also use the history lists,
> and you can enter nothing to repeat the previous query replacement
> operation.)
>
> I don't say that vanilla Emacs should do all of that.  But maybe at
> least something like the third one - a function that returns a string or
> list of strings to be used as default values, and with, as its default
> value, a function that grabs some text at point.

query-replace-regexp already does all the above.  It provides text
at point for first M-n, the last search string for the second M-n, etc.