]> code.delx.au - gnu-emacs-elpa/commitdiff
Rely on window-scroll-functions for scroll blinks
authorTassilo Horn <tsdh@gnu.org>
Thu, 15 Oct 2015 08:55:27 +0000 (10:55 +0200)
committerArtur Malabarba <bruce.connor.am@gmail.com>
Thu, 15 Oct 2015 13:26:50 +0000 (14:26 +0100)
window-scroll-functions are run before the window actually scrolls.  So
just set a flag that it did so which is then picked up and cleared by
beacon--post-command.  Then the redisplay isn't needed there, although
seldomly it seems post-command-hook is run before
window-scroll-functions.  However, the redisplay in beacon--post-command
caused extreme slowdowns when repeatedly deleting text by pressing and
holding DEL in AUCTeX because (I think) every deleted char caused
fontification.

Also fix a problem where the blink occured in the current window whereas
some other window was scrolled, e.g., with the mouse or
scroll-other-window.

beacon.el

index 8a997a1c5dcc392ced9dfaf6322e085f42337c61..acca24d89745ad824c593bd6eb4d1756f0b2e3af 100644 (file)
--- a/beacon.el
+++ b/beacon.el
@@ -204,8 +204,8 @@ Only returns `beacon-size' elements."
 
 \f
 ;;; Movement detection
+(defvar beacon--window-scrolled nil)
 (defvar beacon--previous-place nil)
-(defvar beacon--previous-window-start nil)
 (defvar beacon--previous-mark-head nil)
 
 (defun beacon--movement-> (delta)
@@ -243,9 +243,10 @@ If DELTA is nil, return nil."
         (beacon-blink))))
    ;; Blink for scrolling.
    ((and beacon-blink-when-window-scrolls
-         (progn (redisplay)
-                (not (equal beacon--previous-window-start (window-start)))))
-    (beacon-blink))
+         beacon--window-scrolled)
+    (with-selected-window beacon--window-scrolled
+      (beacon-blink))
+    (setq beacon--window-scrolled nil))
    ;; Blink for movement
    ((beacon--movement-> beacon-blink-when-point-moves)
     (beacon-blink))
@@ -253,10 +254,12 @@ If DELTA is nil, return nil."
    (t (beacon--vanish)))
   (beacon--maybe-push-mark)
   (unless (window-minibuffer-p)
-    (setq beacon--previous-window-start (window-start))
     (setq beacon--previous-mark-head (car mark-ring))
     (setq beacon--previous-place (point-marker))))
 
+(defun beacon--window-scroll-function (win _start-pos)
+  (setq beacon--window-scrolled win))
+
 \f
 ;;; Minor-mode
 (defcustom beacon-lighter (cond
@@ -271,7 +274,10 @@ If DELTA is nil, return nil."
   nil nil beacon-lighter nil
   :global t
   (if beacon-mode
-      (add-hook 'post-command-hook #'beacon--post-command)
+      (progn
+       (add-hook 'window-scroll-functions #'beacon--window-scroll-function)
+       (add-hook 'post-command-hook #'beacon--post-command))
+    (remove-hook 'window-scroll-functions #'beacon--window-scroll-function)
     (remove-hook 'post-command-hook #'beacon--post-command)))
 
 (provide 'beacon)