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: Sat, 18 Feb 2017 00:52:47 +0200 Organization: LINKOV.NET Message-ID: <87poig2zwg.fsf@localhost> References: <87mvdmxoig.fsf@lambda> <87wpcpx32v.fsf@localhost> <83d1ehxqzd.fsf@gnu.org> 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 1487372296 5820 195.159.176.226 (17 Feb 2017 22:58:16 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 17 Feb 2017 22:58:16 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (x86_64-pc-linux-gnu) Cc: 25751@debbugs.gnu.org, antoine.levitt@gmail.com To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Feb 17 23:58:13 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 1cerTd-0000jQ-0R for geb-bug-gnu-emacs@m.gmane.org; Fri, 17 Feb 2017 23:58:09 +0100 Original-Received: from localhost ([::1]:56399 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cerTi-000119-NN for geb-bug-gnu-emacs@m.gmane.org; Fri, 17 Feb 2017 17:58:14 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39570) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cerTZ-0000tb-QG for bug-gnu-emacs@gnu.org; Fri, 17 Feb 2017 17:58:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cerTW-0005Ed-LI for bug-gnu-emacs@gnu.org; Fri, 17 Feb 2017 17:58:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:45700) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cerTW-0005EC-Hf for bug-gnu-emacs@gnu.org; Fri, 17 Feb 2017 17:58:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cerTW-0007j0-6h for bug-gnu-emacs@gnu.org; Fri, 17 Feb 2017 17:58: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: Fri, 17 Feb 2017 22:58: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.148737224729650 (code B ref 25751); Fri, 17 Feb 2017 22:58:02 +0000 Original-Received: (at 25751) by debbugs.gnu.org; 17 Feb 2017 22:57:27 +0000 Original-Received: from localhost ([127.0.0.1]:43899 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cerSx-0007i9-H1 for submit@debbugs.gnu.org; Fri, 17 Feb 2017 17:57:27 -0500 Original-Received: from sub3.mail.dreamhost.com ([69.163.253.7]:34035 helo=homiemail-a17.g.dreamhost.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cerSu-0007hz-SS for 25751@debbugs.gnu.org; Fri, 17 Feb 2017 17:57:25 -0500 Original-Received: from homiemail-a17.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a17.g.dreamhost.com (Postfix) with ESMTP id B8E372B206D; Fri, 17 Feb 2017 14:57:22 -0800 (PST) Original-Received: from localhost.linkov.net (m212-107-59-228.cust.tele2.ee [212.107.59.228]) (Authenticated sender: jurta@jurta.org) by homiemail-a17.g.dreamhost.com (Postfix) with ESMTPA id B49962B206A; Fri, 17 Feb 2017 14:57:21 -0800 (PST) In-Reply-To: <83d1ehxqzd.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 17 Feb 2017 08:37:26 +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:129466 Archived-At: >> > (setq lazy-highlight-initial-delay 0) (shouldn't it be default by th= e >> > way, at least on graphical displays?) reduces the problem but does n= ot >> > 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 replacem= ent. >> I see no simpler solution than to write a new function with a name lik= e >> =E2=80=98isearch-lazy-highlight-update-in-region=E2=80=99 that given t= he region boundaries >> of the last replacement will rehighlight matches in that region. > > I think the problem is not that we remove the highlight and add it > anew, the problem is that there's a redisplay cycle in between the > removal and the following addition. The fact that setting > lazy-highlight-initial-delay alleviates the problem to some extent, > but still leaves the flicker tells me that there's a call to sit-for > or some such somewhere in the code that processes replacements, and > the removal and addition of the highlight are on two different sides > of that sit-for call. One possible solution would be to remove the > highlight and add it without triggering redisplay, then I'd expect the > flicker to go away. > > Does this make sense? This feature is called _lazy_ highlighting where _lazy_ implies that it's intended to highlight matches much later after a lot of redisplay cycles. Currently its steps are the following: 1. Delete old overlays 2. Wait for 0.25 seconds of idle time 3. Highlight first 20 matches 4. Wait 0.0625 seconds 5. Highlight next 20 matches 6. Repeat 4 until all matches are highlighted It makes a big improvement to avoid flicker by moving =E2=80=98Delete old= overlays=E2=80=99 to the end when all new matches are highlighted, essentially extending lazy-highlight with =E2=80=98lazy-cleanup=E2=80=99, i.e. making its clean= up _lazy_ as well. Here is a more tested patch that works especially well for the most frequently used isearch operation of adding characters into the search string - there is no more flicker while typing the search string. diff --git a/lisp/isearch.el b/lisp/isearch.el index 5262435..f8796dd 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) @@ -3122,13 +3123,22 @@ (define-obsolete-variable-alias 'isearch-lazy-hig= hlight-word (defvar isearch-lazy-highlight-forward nil) (defvar isearch-lazy-highlight-error nil) =20 -(defun lazy-highlight-cleanup (&optional force) +(defun lazy-highlight-cleanup (&optional force lazy) "Stop lazy highlighting and remove extra highlighting from current buf= fer. FORCE non-nil means do it whether or not `lazy-highlight-cleanup' is nil. This function is called when exiting an incremental search if `lazy-highlight-cleanup' is non-nil." (interactive '(t)) - (if (or force lazy-highlight-cleanup) + (if (eq lazy t) + (setq isearch-lazy-highlight-overlays-old + (append isearch-lazy-highlight-overlays-old + isearch-lazy-highlight-overlays)) + (while isearch-lazy-highlight-overlays-old + (delete-overlay (car isearch-lazy-highlight-overlays-old)) + (setq isearch-lazy-highlight-overlays-old + (cdr isearch-lazy-highlight-overlays-old)))) + (when (and (or force lazy-highlight-cleanup) + (not lazy)) (while isearch-lazy-highlight-overlays (delete-overlay (car isearch-lazy-highlight-overlays)) (setq isearch-lazy-highlight-overlays @@ -3173,7 +3183,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 + (lazy-highlight-cleanup t (not (equal isearch-string ""))) (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,7 +3325,8 @@ (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)))))))) - (unless nomore + (if nomore + (lazy-highlight-cleanup t 'delete-old) (setq isearch-lazy-highlight-timer (run-at-time lazy-highlight-interval nil 'isearch-lazy-highlight-update)))))))))