Re: [PATCH] Optional preview of the replacement text while typing it

Rahul Martim Juliato <[email protected]> Sat, 08 Aug 2026 19:14:41 -0300
Newsgroups gmane.emacs.devel
Message-ID <[email protected]>
Juri Linkov <[email protected]> writes:

>> [...]
>>   - The preview follows the same shape as the lazy highlight of the
>>     search string (`minibuffer-lazy-highlight-setup' in isearch.el), and
>>     only covers the matches visible in the selected window, so the work
>>     per keystroke is bounded by a screenful.
>
> Have you tried to generalize `minibuffer-lazy-highlight-setup'
> to use for displaying replacements?  For example, by providing
> a lambda to make replacements from the matches.  But probably
> it's not possible to use the argument 'transform' since
> every match might be transformed to different replacements.
> So lazy-highlight would need to display different strings
> instead of one search string like Isearch does.
>

I hadn't considered it before you asked.  Sharing the minibuffer part
looks easy: my 'replace-preview-setup' is nearly a copy of the skeleton
of 'minibuffer-lazy-highlight-setup', and that could be factored out.
Reusing the lazy highlight loop itself seems harder, mostly because it
is asynchronous: the preview uses a display property, so highlighting in
chunks would reflow the buffer in stages on every keystroke.
Zero-length matches also never reach 'isearch-lazy-highlight-match', and
the preview does show those.  I'd rather look into this as a follow-up,
if that's fine with you.


>>   - A replacement that is shorter or longer than the match shifts the
>>     surrounding text while you type, as you can see happening to the
>>     second column between screenshots 03 and 04.  The overlays use a
>>     `display' property, so what you see is the width the buffer will
>>     really have.
>
> Understandable, this should be expected.
>
>> I'd appreciate feedback on both the idea and the implementation. If
>> there is interest in the feature, I'm happy to keep refining the patch.
>
> I tried your patch, and it works nicely, thanks!
>

Happy to hear it :)

> I have more suggestions for additional features, but
> these could be added later.  When no one has more general
> comments, please post the patch to the bug list for pushing.

Done, I opened bug#81583 and posted the patch there.



Gabriel Santos <[email protected]> writes:

> Greetings,
>
> Just tested this. LGTM.
>
> Really excited for this change!

Thanks!


-- 
Rahul Martim Juliato