bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#53126: 29.0.50; [PATCH] Lazy highlight/count when reading query-repl


From: Augusto Stoffel
Subject: bug#53126: 29.0.50; [PATCH] Lazy highlight/count when reading query-replace string, etc.
Date: Wed, 16 Mar 2022 21:09:16 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.91 (gnu/linux)

On Wed, 16 Mar 2022 at 20:56, Juri Linkov <juri@linkov.net> wrote:

>>> So I don't see the need to have this line:
>>>
>>>   (remove-hook 'minibuffer-setup-hook #'minibuffer-lazy-highlight-setup)
>>
>> Okay, but if I remove this line, then all calls to
>> minibuffer-lazy-highlight-setup will require a with-minibuffer-setup
>> hook.  And this will be awkward:
>>
>>      (minibuffer-with-setup-hook (if isearch-lazy-highlight
>>                                       #'minibuffer-lazy-highlight-setup
>>                                     #'ignore)
>>          (read-from-minibuffer "Something: "))
>
> The answer depends on another question: how do you intend the users
> would enable this feature?  When to enable it in all minibuffers
> (like e.g. minibuffer-depth-indicate-mode does) the users will add
> to their init files:
>
>   (add-hook 'minibuffer-setup-hook #'minibuffer-lazy-highlight-setup)
>
> Then removing the user's customization would not be a nice thing to do.
> OTOH, minibuffer-with-setup-hook will remove only own hook, not the user's 
> one.
> So to allow enabling this feature selectively, minibuffer-with-setup-hook
> is not quite awkward.

My idea is:

- The users of the feature are Elisp programmers / package authors.
- I don't think end users can meaningfully do anything directly with
  this new minibuffer hook.
- If package X wants to take advantage of the feature, then it will
  either add minibuffer-lazy-highlight-setup to the
  minibuffer-setup-hook unconditionally, or it will define an
  X-lazy-highlight customization option to control this.

So I think the conclusion is that the current approach in my patch is an
good way to proceed here?

>>> BTW, what is the relation between the minibuffer-lazy-highlight feature
>>> and another proposed feature that immediately updates the search in
>>> the buffer while editing the string in the minibuffer by 
>>> isearch-edit-string?
>>> Can minibuffer-lazy-highlight be considered as a lightweight version of
>>> the buffer search from the minibuffer?
>>
>> Well, there's a package for that on ELPA (isearch-mb), so extending
>> isearch-edit-string to do that seems superfluous now?
>
> It's still possible to add this feature to isearch-edit-string,
> when the change would not be too enormous.  I recall squeezing
> it into a small patch, but unfortunately it requires changes
> in keymap priorities.

I would suggest taking a look at isearch-mb.  I think the code is pretty
tight, and I would be unable to shorten the implementation other than by
deleting comment :-)

>>>> There are a few more we could add   (perhaps later),
>>>> such as `occur' and `keep-lines'.
>>>
>>> I tried (add-hook 'minibuffer-setup-hook #'minibuffer-lazy-highlight-setup)
>>> in the minibuffer of 'occur' and others, and it works nicely.
>>> Maybe it could even semi-deprecate the package re-builder.el.
>>>
>>> Thanks for this generally usable feature.
>>
>> By the way, this is a byproduct of that long discussion that led to
>> isearch-mb, so it was not all in vain :-).
>
> Are you sure these features can't be combined?  One feature basically
> runs isearch-search-and-update in the buffer from the minibuffer,
> and this feature runs isearch-lazy-highlight-new-loop.

For one thing, isearch-mode has 2 essential commands (repeat forward and
backwards), a couple more necessary ones (quit, abort, scroll,
beginning/end of buffer, mode toggles), and then a number of commands
that end the search with a special action (query-replace, etc.).

These little details add up to the 283 lines in isearch-mb.el currently
has.

>>>> - There's no customization variable to enable the minibuffer lazy
>>>>   highlight.  The rationale is that each command that will use it should
>>>>   define its own user option (or use an existing one).  For
>>>>   `isearch-edit-string' it's `isearch-lazy-highlight'; for
>>>>   `query-replace' it's `query-replace-lazy-highlight'; and so on.
>>>
>>> A common customizable option to enable this everywhere would be nice too.
>>> Maybe disabling is already possible by customizing
>>> 'minibuffer-lazy-count-format' to nil?  Then the checks for
>>> non-nil 'minibuffer-lazy-count-format' could be added to
>>> more places, such as to wrap the whole '(condition-case error'
>>> in query-replace-read-args with the 'when' condition, etc.
>>
>> Yes, the user can set minibuffer-lazy-count-format to nil to get rid of
>> the lazy count.
>>
>> Concerning query-replace, why would anyone want to have lazy highlight
>> during the perform-replace loop, but not earlier?  I'm not a fan of
>> adding a custom option here, not because it would be hard, but because
>> it seems totally unnecessary.
>
> Maybe a new option would make sense for the same reason why there is
> the option isearch-lazy-count?

Okay, I'm not against this, but let's think about the names of these user
options.  The existing option is named query-replace-lazy-highlight,
which seems to exactly describe the new feature.  The existing feature
would more specifically be called perform-replace-lazy highlight.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]