]> git.cworth.org Git - notmuch/commitdiff
emacs: replace use of hook to draw hl-line in search mode
authorDavid Bremner <david@tethera.net>
Sat, 10 Aug 2024 17:36:22 +0000 (14:36 -0300)
committerDavid Bremner <david@tethera.net>
Thu, 13 Mar 2025 10:48:53 +0000 (07:48 -0300)
In the thread at id:87fsfuuxwn.fsf@thinkbox, a bug is discussed where
the point and hl-line overlay get out of sync, leading the user to
open the wrong message. As far as I can tell this is caused by
notmuch-hl-mode being invoked too early.

This change bypasses the logic preventing notmuch-search-hook being
called only once, so that the overlay is updated later after the
buffer is full(er).

This change may lead to the overlay being updated multiple times; if
this is annoying we can add a similar buffer local variable to ensure
it is only called once.

The extra logic to check notmuch-search-target-line reduces the
flicker somewhat by not highlighting the first line every time.

emacs/notmuch.el
test/T312-emacs-hl-line.sh

index 934ec8945b2f7d1d01201c66046a7245888210d2..5477bf4a715ecab5cc7d0e4ab7c9d9166aa46aa3 100644 (file)
@@ -126,10 +126,9 @@ there will be called at other points of notmuch execution."
   :type 'file
   :group 'notmuch)
 
-(defcustom notmuch-search-hook '(notmuch-hl-line-mode)
+(defcustom notmuch-search-hook nil
   "List of functions to call when notmuch displays the search results."
   :type 'hook
-  :options '(notmuch-hl-line-mode)
   :group 'notmuch-search
   :group 'notmuch-hooks)
 
@@ -930,6 +929,16 @@ sets the :orig-tag property."
        (notmuch-sexp-parse-partial-list 'notmuch-search-append-result
                                         results-buf))
       (with-current-buffer results-buf
+       (when (and notmuch-hl-line
+                  ;; If we know where the cursor will end up (from
+                  ;; the call to notmuch-search), avoid redrawing the
+                  ;; hl-line overlay until the buffer is sufficiently
+                  ;; filled. This check is intended as an
+                  ;; optimization to reduce flicker.
+                  (>=
+                   (line-number-at-pos (point-max) t)
+                   (or notmuch-search-target-line -1)))
+         (notmuch-hl-line-mode))
        (notmuch--search-hook-wrapper)))))
 
 ;;; Commands (and some helper functions used by them)
index 4cceed30940d5f9a28a4a411e61a84a06124976a..4697b67157d7b6791686d0803ec16ea11d2c89c1 100755 (executable)
@@ -104,7 +104,6 @@ test_emacs_expect_t '(let ((notmuch-hl-line t))
                           (line-number-at-pos (overlay-start hl-line-overlay)) 12))'
 
 test_begin_subtest "line 12, search, refresh"
-test_subtest_known_broken
 test_emacs_expect_t '(let ((notmuch-hl-line t))
                        (notmuch-search "tag:inbox")
                        (notmuch-test-wait)
@@ -140,7 +139,6 @@ test_emacs_expect_t '(let ((notmuch-hl-line t))
                           (line-number-at-pos (overlay-start hl-line-overlay)) 12))'
 
 test_begin_subtest "hl-line disabled, search"
-test_subtest_known_broken
 test_emacs_expect_t '(let ((notmuch-hl-line nil))
                        (notmuch-search "tag:inbox")
                        (notmuch-test-wait)