From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Augusto Stoffel Newsgroups: gmane.emacs.devel Subject: Patch to avoid flicker in Isearch with lazy count Date: Wed, 27 Jan 2021 16:41:28 +0100 Message-ID: <87r1m6jsk7.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38340"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Jan 27 16:42:23 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l4mxa-0009p5-Fh for ged-emacs-devel@m.gmane-mx.org; Wed, 27 Jan 2021 16:42:22 +0100 Original-Received: from localhost ([::1]:54400 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l4mxZ-0002oA-Gq for ged-emacs-devel@m.gmane-mx.org; Wed, 27 Jan 2021 10:42:21 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39592) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l4mwo-0002Ja-LE for emacs-devel@gnu.org; Wed, 27 Jan 2021 10:41:34 -0500 Original-Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]:35789) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l4mwm-00011u-Pi for emacs-devel@gnu.org; Wed, 27 Jan 2021 10:41:34 -0500 Original-Received: by mail-ej1-x632.google.com with SMTP id ox12so3298209ejb.2 for ; Wed, 27 Jan 2021 07:41:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:user-agent:mime-version; bh=Ual/jgtg5acX9HyhGeLqIeI19JjyJSxYzU0VXrscdKo=; b=ZnZuDaRswe7cWrMCc2rAR4ofw+ooVQwXFcNGAoZZ3omBZpvwaawqURxGaAuhDSxIDe PDG/Cir/30OOvalDs6w8HaFkDvfCv+GRrcbPle5Xn0nhLPo6/YV8Re5Tt7JXLP4iVTQS 8wYx2ifVsLKaecVutRvdld88R/v1n1xx0tkIYI8oBrIdm7sc58xJ280CX8f8qKa+XEPP yB3Zn9GLN8B4wFavcu8KbHcT9fO5tJyHwtstGQuNoaRL7+3C6iS1qb8QvOcqF0Xc+pbR OCUggqwfzsC13lSFrNjAuzG2K0LAZKP7gYdq50llBlfA4B8woWUFldfVg9qDVRhxkodi KOZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:user-agent :mime-version; bh=Ual/jgtg5acX9HyhGeLqIeI19JjyJSxYzU0VXrscdKo=; b=iuhMD2cKoAVT4VM+9pnzxVDUf+pPmvXjrrEbXSm53pklqpZ9fg77ClFFDuf+KhGcwy ZX1CnEd55O37HKOcZmued0rfQO9AjbzrmnM+903DgzMmzA611XL2Nw+MqVrcrDfQ4QAo HqsUrSvQWbmKpa4XYJVff85vV5AdbuVW1fZXBu1PNMYq8c/NNeqzGa218fEhfHe5eiVK evK8H+xZaDc0v/qoSWoAQgD5ph14EVbnNZ1yRJAotOJQdQq5d2xEW2fqPjk6pdl2Osxa u54ZA5nRwOTaToBX3ViPKAsde4e4qkRst6FYVQAdIyZNcct+eDLilH3jJV910g6iYA1Q cjyw== X-Gm-Message-State: AOAM531YKC68RcATb3GJfxw6jc6K4QYsIXgzdeEIEZKvSd12nWLbYZZA z7H4lteJpk5DSiJHw1lvxpjbY1HsNcs= X-Google-Smtp-Source: ABdhPJwyPEODBx7g7ddsrIG/BwKE5lz8DGSSbZZCQFwmXnpAkYQBv3eMmQ1BjErRUfsxxNntuh5lkA== X-Received: by 2002:a17:906:30c4:: with SMTP id b4mr7250787ejb.456.1611762090605; Wed, 27 Jan 2021 07:41:30 -0800 (PST) Original-Received: from ars3 ([2a02:908:2211:8540::16e5]) by smtp.gmail.com with ESMTPSA id g14sm1521385edm.31.2021.01.27.07.41.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Jan 2021 07:41:29 -0800 (PST) Received-SPF: pass client-ip=2a00:1450:4864:20::632; envelope-from=arstoffel@gmail.com; helo=mail-ej1-x632.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:263509 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Setting =E2=80=98lazy-highlight-initial-delay=E2=80=99 to 0 (which should b= e a reasonable default on a modern machine) causes some flickering in the search buffer, and a lot of flickering in the echo are when =E2=80=98isearch-lazy-count=E2=80=99 is on. The attached patch addresses these problems. It also makes the desired effect of setting =E2=80=98lazy-highlight-initial-delay=E2=80=99 to= 0 the default, even though that variable is unchanged. Flicker in the search buffer happens because the highlighting of matches happens after typing just one letter, and there are potentially many of those. It is fixed by adding a new variable, =E2=80=98lazy-highlight-delay-max-chars=E2=80=99. Lazy highlighting kicks = in immediately if the search string is longer than that number. I set the default value to 2, but maybe 1 is even better. Flicker in the echo area happens even with the default value of =E2=80=98lazy-highlight-initial-delay=E2=80=99, if less pronouncedly, and i= s due to too frequent updates to the echo area message. This is solved by keeping the lazy count in the echo area of out of date for the fraction of a second where the lazy stuff is waiting to kick in. Please let me know if this works well and can be merged. Best, Augusto --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Reduce-flicker-in-Isearch-mode.patch >From aaef7a6438aaa74a5978e5e9d4b5e95910c2b15e Mon Sep 17 00:00:00 2001 From: Augusto Stoffel Date: Wed, 27 Jan 2021 16:09:38 +0100 Subject: [PATCH] Reduce flicker in Isearch mode Lazy highlighting now happens immediately (only) if the search string is longer than the value of the new custom variable `lazy-highlight-delay-max-chars`. Also avoid updating the lazy count in the echo area too often. * isearch.el (lazy-highlight-delay-max-chars): new defcustom * isearch.el (isearch-lazy-highlight-with-timer): new function, factors out a repeated snippet of code. * isearch.el (isearch-lazy-highlight-new-loop, isearch-lazy-highlight-update, isearch-lazy-highlight-buffer-update): use the new `isearch-lazy-highlight-with-timer` function. * isearch.el (isearch-lazy-highlight-new-loop): avoid a call to `isearch-message` that is quickly succeed by a second echo area update, thus causing flicker. --- lisp/isearch.el | 48 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/lisp/isearch.el b/lisp/isearch.el index a86678572c..ca0fd1434a 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -352,12 +352,22 @@ lazy-highlight-cleanup :group 'lazy-highlight) (defcustom lazy-highlight-initial-delay 0.25 - "Seconds to wait before beginning to lazily highlight all matches." + "Seconds to wait before beginning to lazily highlight all matches. +This setting only has effect if the current search string is at most +`lazy-highlight-initial-delay' character long." :type 'number :group 'lazy-highlight) +(defcustom lazy-highlight-delay-max-chars 2 + "Size of a search string above which lazy highlight happens immediately." + :type 'number + :group 'lazy-highlight + :version "28.1") + (defcustom lazy-highlight-interval 0 ; 0.0625 - "Seconds between lazily highlighting successive matches." + "Seconds between lazily highlighting successive matches. +This setting only has effect if the current search string is at most +`lazy-highlight-initial-delay' character long." :type 'number :group 'lazy-highlight) @@ -3357,7 +3367,7 @@ isearch-lazy-count-format (not isearch-error) (not isearch-suspended)) (format format-string - (if isearch-forward + (if isearch-lazy-highlight-forward isearch-lazy-count-current (if (eq isearch-lazy-count-current 0) 0 @@ -3858,6 +3868,15 @@ lazy-highlight-cleanup (cancel-timer isearch-lazy-highlight-timer) (setq isearch-lazy-highlight-timer nil))) +(defun isearch-lazy-highlight-with-timer (delay function) + "Arrange for FUNCTION to be called in idle time, possibly with DELAY. +There is no delay if the current search string is longer than +`lazy-highlight-delay-max-chars'." + (setq isearch-lazy-highlight-timer + (run-with-idle-timer + (if (> (length isearch-string) lazy-highlight-delay-max-chars) 0 delay) + nil function))) + (defun isearch-lazy-highlight-new-loop (&optional beg end) "Cleanup any previous `lazy-highlight' loop and begin a new one. BEG and END specify the bounds within which highlighting should occur. @@ -3917,7 +3936,8 @@ isearch-lazy-highlight-new-loop (clrhash isearch-lazy-count-hash) (setq isearch-lazy-count-current nil isearch-lazy-count-total nil) - (isearch-message))) + ;; Delay updating the message if possible, to avoid flicker + (when (string-equal isearch-string "") (isearch-message)))) (setq isearch-lazy-highlight-window-start-changed nil) (setq isearch-lazy-highlight-window-end-changed nil) (setq isearch-lazy-highlight-error isearch-error) @@ -3961,9 +3981,8 @@ isearch-lazy-highlight-new-loop (1- (length isearch-lazy-highlight-last-string))) (point-min)))) (unless (equal isearch-string "") - (setq isearch-lazy-highlight-timer - (run-with-idle-timer lazy-highlight-initial-delay nil - 'isearch-lazy-highlight-start)))) + (isearch-lazy-highlight-with-timer lazy-highlight-initial-delay + 'isearch-lazy-highlight-start))) ;; Update the current match number only in isearch-mode and ;; unless isearch-mode is used specially with isearch-message-function (when (and isearch-lazy-count isearch-mode (null isearch-message-function)) @@ -4101,12 +4120,10 @@ isearch-lazy-highlight-update (if isearch-lazy-highlight-forward (setq isearch-lazy-highlight-end (point-min)) (setq isearch-lazy-highlight-start (point-max))) - (setq isearch-lazy-highlight-timer - (run-at-time lazy-highlight-interval nil - 'isearch-lazy-highlight-buffer-update))) - (setq isearch-lazy-highlight-timer - (run-at-time lazy-highlight-interval nil - 'isearch-lazy-highlight-update))))))))) + (isearch-lazy-highlight-with-timer + lazy-highlight-interval 'isearch-lazy-highlight-buffer-update)) + (isearch-lazy-highlight-with-timer + lazy-highlight-interval 'isearch-lazy-highlight-update)))))))) (defun isearch-lazy-highlight-buffer-update () "Update highlighting of other matches in the full buffer." @@ -4180,9 +4197,8 @@ isearch-lazy-highlight-buffer-update (setq isearch-lazy-count-current (gethash opoint isearch-lazy-count-hash 0)) (isearch-message)) - (setq isearch-lazy-highlight-timer - (run-at-time lazy-highlight-interval nil - 'isearch-lazy-highlight-buffer-update))))))))) + (isearch-lazy-highlight-with-timer + lazy-highlight-interval 'isearch-lazy-highlight-buffer-update)))))))) (defun isearch-resume (string regexp word forward message case-fold) "Resume an incremental search. -- 2.29.2 --=-=-=--