Subject: RE: [External] : bug#54086: Occur should offer more interactive input options

From: Drew Adams <[email-masked]>
Date: Mon, 21 Feb 2022 17:13:18 +0000

> something like this for initial input :
> (if (use-region-p)
>     (buffer-substring (region-beginning) (region-end))
>   (thing-at-point 'symbol))

As Lars pointed out, you can use `M-n' to
retrieve such a default input (and there can
be multiple reasonable default inputs - repeat
`M-n' to access them).

However, when the region is active there are
two different (i.e., alternative) behaviors
that can be useful:

 1. Use the region content as the text to find.
    (This is what you suggested.)
 2. Limit searching to the region.

#2 is very useful.  (You can of course narrow
to the region and then search, but it helps to
be able to see the surrounding text while you
search only the region text.)

Users should have a way to choose which of the
behaviors they prefer by default and to change
to the other alternative on the fly (without
having to change their default choice by, e.g.,
flipping an option value).

With library `isearch+.el' you can limit
searching to the region: use non-nil option
`search/replace-region-as-default-flag'.

And not only Isearch.  If you also use library
`replace+.el' then `occur' and all replace
commands also respect the option.

To prefer using the region content as what to
search for, leave the option as nil and use a
function that does what your `if' does as the
value of option `search/replace-default-fn'.
___

isearch+.el:

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

replace+.el:

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