unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Augusto Stoffel <arstoffel@gmail.com>
To: Juri Linkov <juri@linkov.net>, emacs-devel@gnu.org
Subject: Re: Patch to avoid flicker in Isearch with lazy count
Date: Fri, 29 Jan 2021 18:50:21 +0100	[thread overview]
Message-ID: <87tuqzzl7m.fsf@gmail.com> (raw)
In-Reply-To: <871re5e809.fsf@mail.linkov.net> (Juri Linkov's message of "Thu,  28 Jan 2021 11:06:38 +0200")

[-- Attachment #1: Type: text/plain, Size: 496 bytes --]

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 ‘lazy-highlight-buffer-max-at-a-time’ 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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Reduce-flicker-in-Isearch-mode.patch --]
[-- Type: text/x-patch, Size: 5082 bytes --]

From 2562d8b3b804729310590b1d689ce5a7c6ff2ea0 Mon Sep 17 00:00:00 2001
From: Augusto Stoffel <arstoffel@gmail.com>
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-<return> instead of <C-M-return>.  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.
+
 \f
 * 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


  parent reply	other threads:[~2021-01-29 17:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-27 15:41 Patch to avoid flicker in Isearch with lazy count Augusto Stoffel
2021-01-27 17:48 ` Juri Linkov
2021-01-28  7:32   ` Augusto Stoffel
2021-01-28  9:06     ` Juri Linkov
2021-01-28 11:17       ` Augusto Stoffel
2021-01-28 18:48         ` Juri Linkov
2021-01-29 17:50       ` Augusto Stoffel [this message]
2021-01-30 18:50         ` Juri Linkov
2021-09-04 22:43           ` Stefan Kangas
2021-09-05  7:54             ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87tuqzzl7m.fsf@gmail.com \
    --to=arstoffel@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=juri@linkov.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).