From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#25751: Query replace lazy highlighting Date: Fri, 17 Feb 2017 00:45:05 +0200 Organization: LINKOV.NET Message-ID: <87vas9sqku.fsf@localhost> References: <87mvdmxoig.fsf@lambda> <87wpcpx32v.fsf@localhost> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1487285294 11452 195.159.176.226 (16 Feb 2017 22:48:14 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 16 Feb 2017 22:48:14 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (x86_64-pc-linux-gnu) Cc: 25751@debbugs.gnu.org To: Antoine Levitt Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Feb 16 23:48:10 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ceUqM-0002Pd-PN for geb-bug-gnu-emacs@m.gmane.org; Thu, 16 Feb 2017 23:48:06 +0100 Original-Received: from localhost ([::1]:50653 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceUqS-0004mz-CJ for geb-bug-gnu-emacs@m.gmane.org; Thu, 16 Feb 2017 17:48:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60411) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceUqM-0004l4-3w for bug-gnu-emacs@gnu.org; Thu, 16 Feb 2017 17:48:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceUqI-0001eJ-SZ for bug-gnu-emacs@gnu.org; Thu, 16 Feb 2017 17:48:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:44563) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ceUqI-0001dn-PL for bug-gnu-emacs@gnu.org; Thu, 16 Feb 2017 17:48:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ceUqI-0004Ec-Eo for bug-gnu-emacs@gnu.org; Thu, 16 Feb 2017 17:48:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 16 Feb 2017 22:48:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25751 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 25751-submit@debbugs.gnu.org id=B25751.148728523016213 (code B ref 25751); Thu, 16 Feb 2017 22:48:02 +0000 Original-Received: (at 25751) by debbugs.gnu.org; 16 Feb 2017 22:47:10 +0000 Original-Received: from localhost ([127.0.0.1]:42762 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ceUpQ-0004DP-Cd for submit@debbugs.gnu.org; Thu, 16 Feb 2017 17:47:08 -0500 Original-Received: from sub3.mail.dreamhost.com ([69.163.253.7]:34130 helo=homiemail-a39.g.dreamhost.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ceUpP-0004DI-76 for 25751@debbugs.gnu.org; Thu, 16 Feb 2017 17:47:07 -0500 Original-Received: from homiemail-a39.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a39.g.dreamhost.com (Postfix) with ESMTP id 8A4F415006D; Thu, 16 Feb 2017 14:47:04 -0800 (PST) Original-Received: from localhost.linkov.net (m83-191-240-183.cust.tele2.ee [83.191.240.183]) (Authenticated sender: jurta@jurta.org) by homiemail-a39.g.dreamhost.com (Postfix) with ESMTPA id B41E2150069; Thu, 16 Feb 2017 14:47:03 -0800 (PST) In-Reply-To: <87wpcpx32v.fsf@localhost> (Juri Linkov's message of "Thu, 16 Feb 2017 23:01:28 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:129426 Archived-At: >> When query-replacing and confirming, matches get unhighlighted, and th= en >> 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 replaceme= nt. > I see no simpler solution than to write a new function with a name like > =E2=80=98isearch-lazy-highlight-update-in-region=E2=80=99 that given th= e region boundaries > of the last replacement will rehighlight matches in that region. Actually, there are too many special casing to optimize that makes this solution too brittle: for example, replacing a string with shorter text requires highlighting new matches at the window-end minus the length of t= he deleted text, i.e. deletion shifts previously invisible text into the vie= w where matches should be highlighted. But I realized that fortunately there is a better and simpler solution. The problem is not specific to replacement, the same flicker exists in is= earch, e.g. while scrolling by one line where all overlays are deleted, and created again in the same places. To void flickering the best solution i= s to delete old overlays AFTER adding new ones, not BEFORE as it is now - this works pleasingly well: diff --git a/lisp/isearch.el b/lisp/isearch.el index 5262435..9cb5399 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -3101,6 +3101,7 @@ (defun isearch-dehighlight () ;; only if `isearch-string' is an invalid regexp. =20 (defvar isearch-lazy-highlight-overlays nil) +(defvar isearch-lazy-highlight-overlays-old nil) (defvar isearch-lazy-highlight-wrapped nil) (defvar isearch-lazy-highlight-start-limit nil) (defvar isearch-lazy-highlight-end-limit nil) @@ -3173,7 +3174,7 @@ (defun isearch-lazy-highlight-new-loop (&optional b= eg end) (not (equal isearch-error isearch-lazy-highlight-error)))) ;; something important did indeed change - (lazy-highlight-cleanup t) ;kill old loop & remove overlays + (setq isearch-lazy-highlight-overlays-old isearch-lazy-highlight-ove= rlays) (setq isearch-lazy-highlight-error isearch-error) ;; It used to check for `(not isearch-error)' here, but actually ;; lazy-highlighting might find matches to highlight even when @@ -3315,6 +3316,11 @@ (defun isearch-lazy-highlight-update () (setq isearch-lazy-highlight-start (window-group-end)) (goto-char (min (or isearch-lazy-highlight-end-limit (point-max)) (window-group-end)))))))) + (when nomore + ;; Remove old overlays + (let ((isearch-lazy-highlight-overlays isearch-lazy-highli= ght-overlays-old) + (isearch-lazy-highlight-timer nil)) + (lazy-highlight-cleanup t))) (unless nomore (setq isearch-lazy-highlight-timer (run-at-time lazy-highlight-interval nil