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: Re: Patch to avoid flicker in Isearch with lazy count Date: Fri, 29 Jan 2021 18:50:21 +0100 Message-ID: <87tuqzzl7m.fsf@gmail.com> References: <87r1m6jsk7.fsf@gmail.com> <87lfce2ruh.fsf@mail.linkov.net> <87tur1bjof.fsf@gmail.com> <871re5e809.fsf@mail.linkov.net> 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="15676"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) To: Juri Linkov , emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Jan 29 18:54:59 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 1l5Xz1-0003xX-FU for ged-emacs-devel@m.gmane-mx.org; Fri, 29 Jan 2021 18:54:59 +0100 Original-Received: from localhost ([::1]:49906 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l5Xz0-0008D2-HO for ged-emacs-devel@m.gmane-mx.org; Fri, 29 Jan 2021 12:54:58 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53716) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l5Xuf-000333-A4 for emacs-devel@gnu.org; Fri, 29 Jan 2021 12:50:31 -0500 Original-Received: from mail-ej1-x633.google.com ([2a00:1450:4864:20::633]:38669) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l5Xub-0005wn-Rm for emacs-devel@gnu.org; Fri, 29 Jan 2021 12:50:29 -0500 Original-Received: by mail-ej1-x633.google.com with SMTP id bl23so14272655ejb.5 for ; Fri, 29 Jan 2021 09:50:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=8T2wYvp0IctxIhpsnmBIHqSrMJEpe5ZeWyOcJFlY/44=; b=WYDYR44eN1aa47u6coj21N7al95ms9eXeQX786JteNnFiqmrWC0sb+XBF/ajQ977yc L1WmKZHRarXF43qBkwTUyOWIWekuEg7W09yn+Jntcj4anL6JLFSUKmmqkLFaSDMmK/oU WfYsAQoRO4jOPNDix5FnE4f4hxLeF8W9r/3xwvFMkHOQ60lh7JP0DNXXTMEUnEVfZ88R OWSQjY1Cl6hgbjlQRN2xHU6aLm8kn0ZzdNImwIY1hNf3ZKSyr6jjqV1zy7CXaOpT+pxC bUbigbqkWNNl6mC+2EX/AVXtyez8QtokaefyEjK3S2kyXtKqc+WoeGqQMwzV50Fl0kKd 3oIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=8T2wYvp0IctxIhpsnmBIHqSrMJEpe5ZeWyOcJFlY/44=; b=Mz5JrJE2V1/6p/MES18NkQMYzj7YYqIvxOPMWbQTMQo5nNBy/6p0NMomvMNQ8nzTy5 VQXtVqE/DVnvQkmh5ApE9TGPwF7VNDrfhU3RZNOSW2w0t66xaNke4FG5B4Z8Png+6KGB Z4GMfGG7faAD0YwsNoItuhjflzD2No3oJuh+OeksTeofBLWZQe4HBdh+uJY67jGU9sVG Y9WLkSutAMoQwGxzevaPqkte8ce+msf26BO3QjjGehDhqZRWiM6ERYj5TRB7CBbBXwno pM05S/sQI18TW5nA1lSAB8W7wS9UKAQl/5En1G2wDV3URm6yZX3ldptFn/ehZANa5SEj BmmQ== X-Gm-Message-State: AOAM530RBoccCwG5+We7nh030UB3MMe/p0fkQnwHFFx7IanXE76XGM3w URrHHAkauHDnuFqMCZ8DwtOH0IYtea0= X-Google-Smtp-Source: ABdhPJxFf8nQf8v3VGng623syw4YuMdsVrGmtIrgWBw8f0h63TjRi7nJPLjmJ2g5KjwwVqnJbxvifw== X-Received: by 2002:a17:907:3345:: with SMTP id yr5mr5934693ejb.50.1611942623584; Fri, 29 Jan 2021 09:50:23 -0800 (PST) Original-Received: from ars3 ([2a02:908:2211:8540::16e5]) by smtp.gmail.com with ESMTPSA id w8sm3986603edd.39.2021.01.29.09.50.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jan 2021 09:50:22 -0800 (PST) In-Reply-To: <871re5e809.fsf@mail.linkov.net> (Juri Linkov's message of "Thu, 28 Jan 2021 11:06:38 +0200") Received-SPF: pass client-ip=2a00:1450:4864:20::633; envelope-from=arstoffel@gmail.com; helo=mail-ej1-x633.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:263582 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Juri, I have attached a new patch addressing the issues we discussed. I have also changed the name of the new variable a bit, I hope it's a bit more self-explanatory now. I have also tested increasing =E2=80=98lazy-highlight-buffer-max-at-a-time= =E2=80=99 to 1000. I can't see any loss in responsiveness, except when the old value of 20 also makes the editor freeze (for instance when searching for ".*a.*a$" in very large buffer). This is probably a reasonable default. Best, Augusto --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Reduce-flicker-in-Isearch-mode.patch >From 2562d8b3b804729310590b1d689ce5a7c6ff2ea0 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 when the search string is at least as long as the value of the new custom variable `lazy-highlight-delay-no-delay-length`. Also avoid updating the lazy count in the echo area too often. * isearch.el (lazy-highlight-delay-no-delay-length): new defcustom * isearch.el (lazy-lazy-count-format): avoid a momentarily incorrect count when reversing search direction. * 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. * isearch.el (isearch-lazy-highlight-new-loop): start lazy highlight immediately if appropriate. * etc/NEWS: Announce the change. * lisp/iserch.el: Document `lazy-highlight-delay-no-delay-length' --- doc/emacs/search.texi | 7 +++++++ etc/NEWS | 7 +++++++ lisp/isearch.el | 23 +++++++++++++++++++---- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/doc/emacs/search.texi b/doc/emacs/search.texi index 637867b811..f3c42bcea7 100644 --- a/doc/emacs/search.texi +++ b/doc/emacs/search.texi @@ -2027,6 +2027,13 @@ Search Customizations @item lazy-highlight-initial-delay @vindex lazy-highlight-initial-delay Time in seconds to wait before highlighting visible matches. +Applies only if the search string is less than +@code{lazy-highlight-no-delay-length} characters long. + +@item lazy-highlight-no-delay-length +@vindex lazy-highlight-no-delay-length +For search strings at least as long as the value of this variable, +lazy highlighting of matches starts immediately. @item lazy-highlight-interval @vindex lazy-highlight-interval diff --git a/etc/NEWS b/etc/NEWS index e038076e96..becda4bc6b 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -226,6 +226,13 @@ C-M- instead of . Either variant can be used as input; functions such as 'kbd' and 'read-kbd-macro' accept both styles as equivalent (they have done so for a long time). ++++ +** New user option 'lazy-highlight-no-delay-length'. +Lazy highlighting of matches in Isearch now starts immediately if the +search string is at least this long. 'lazy-highlight-initial-delay' +still applies for shorter search strings, which avoids flicker in the +search buffer due to too many matches being highlighted. + * Editing Changes in Emacs 28.1 diff --git a/lisp/isearch.el b/lisp/isearch.el index a86678572c..a1c393c9ee 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -352,10 +352,20 @@ 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 when the search string is less than +`lazy-highlight-no-delay-length' characters long." :type 'number :group 'lazy-highlight) +(defcustom lazy-highlight-no-delay-length 3 + "For search strings at least this long, lazy highlight starts immediately. +For shorter search strings, `lazy-highlight-initial-delay' +applies." + :type 'number + :group 'lazy-highlight + :version "28.1") + (defcustom lazy-highlight-interval 0 ; 0.0625 "Seconds between lazily highlighting successive matches." :type 'number @@ -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 @@ -3917,7 +3927,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) @@ -3962,7 +3973,11 @@ isearch-lazy-highlight-new-loop (point-min)))) (unless (equal isearch-string "") (setq isearch-lazy-highlight-timer - (run-with-idle-timer lazy-highlight-initial-delay nil + (run-with-idle-timer (if (>= (length isearch-string) + lazy-highlight-no-delay-length) + 0 + lazy-highlight-initial-delay) + nil 'isearch-lazy-highlight-start)))) ;; Update the current match number only in isearch-mode and ;; unless isearch-mode is used specially with isearch-message-function -- 2.29.2 --=-=-=--