Subject: bug#25751: Query replace lazy highlighting

From: Juri Linkov <[email-masked]>
Date: Thu, 16 Feb 2017 23:01:28 +0200

> When query-replacing and confirming, matches get unhighlighted, and then
> highlighted again, which is very distracting. E.g. open a file, M-% a ->
> a, y, other matches of a get unhighlighted then highlighted again.
>
> (setq lazy-highlight-initial-delay 0) (shouldn't it be default by the
> way, at least on graphical displays?) reduces the problem but does not
> eliminate it (it produces small flickers). There's
> lazy-highlight-cleanup, but that disables cleanup completely, which I
> don't want.
>
> Can't this be eliminated?

The reason why it works this way is because lazy-highlight is not yet
optimized to handle changes: it needs to dehighlight the replaced text,
and to add highlighting in the new replacing text after every replacement.
I see no simpler solution than to write a new function with a name like
‘isearch-lazy-highlight-update-in-region’ that given the region boundaries
of the last replacement will rehighlight matches in that region.