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

From: Drew Adams <[email-masked]>
Date: Thu, 4 Jun 2020 16:01:21 -0700 (PDT)

> Currently `query-replace-read-from' has:
>   (if regexp-flag
>       (read-regexp prompt nil 'minibuffer-history)
>     (read-from-minibuffer
>       prompt nil nil nil nil (car search-ring) t))
> 
> It's easy to extend `read-regexp' with more options,
> but what to do for non-regexp case?
> 
> Maybe to try to use `read-string' and extend it with
> more M-n options like in `read-regexp'.

I don't understand the question.  `read-from-minibuffer'
accepts a list of default values.  Or maybe I don't
understand what you mean by "more options".

I think I referred you to my code in `replace+.el'.
Here it is, in case I didn't:

https://www.emacswiki.org/emacs/download/replace%2b.el

In my code for `query-replace-read-from' I determine
the default value(s) by evaluating this:
(search/replace-default
  (symbol-value query-replace-from-history-variable))

I use function `search/replace-default' in lots of
search and replace functions.  It's the place where
this logic is used to get default values:

 Return a default value or list of such for search &
 replace functions.
 A list of default input strings is computed and
 returned.  The possible strings are, in order:

 * The active region, if option
   `search/replace-region-as-default-flag' is non-nil.

 * The secondary selection, if option
   `search/replace-2nd-sel-as-default-flag' is non-nil.

 * The result of calling the value of option
   `search/replace-default-fn', if non-nil.

 * The first entry in the history list HISTORY.

Option `search/replace-default-fn' lets users decide
what function to use, to grab buffer text as the
default.  The option's default value is a function
that grabs the non-nil symbol name that's nearest point.
If that function isn't available then the default value
is `word-at-point'.

HTH.