Re: [PATCH] Optional preview of the replacement text while typing it
Juri Linkov <[email protected]> Thu, 06 Aug 2026 20:52:11 +0300
| Newsgroups | gmane.emacs.devel |
|---|---|
| Organization | LINKOV.NET |
| Message-ID | <[email protected]> |
> So I'm proposing an optional preview feature: while the replacement > string is being read, the matches visible in the window are displayed as > they would look after the replacement, using a new face > `query-replace-preview'. This feature is very much welcome. > The patch is attached. Thanks for the patch. > - The new option `query-replace-show-preview' defaults to nil. Since > this is a visual change to the buffer, I think opting in is the > safer call, though it is debatable, and I am happy to flip it. Agreed, nil by default is safer. > - 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. > - 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! 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.