From 13a9fde7a9b0a4f7a40e6d5e9ce3447bbfed777b Mon Sep 17 00:00:00 2001 From: Chow Loong Jin Date: Fri, 24 Jan 2014 09:47:19 +0800 Subject: [PATCH] Add customization option to delay linum updates When linum-schedule is called many times in quick succession, delay the update by linum-delay-seconds, and coalesce all calls to linum-update-current to avoid useless repeated calls. Signed-off-by: Chow Loong Jin --- lisp/linum.el | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lisp/linum.el b/lisp/linum.el index d91ce11..50759b5 100644 --- a/lisp/linum.el +++ b/lisp/linum.el @@ -37,6 +37,7 @@ (defvar linum-available nil "Overlays available for reuse.") (defvar linum-before-numbering-hook nil "Functions run in each buffer before line numbering starts.") +(defvar linum-timer-object nil "Timer object for use with ilnum-delay") (mapc #'make-variable-buffer-local '(linum-overlays linum-available)) @@ -71,6 +72,10 @@ and you have to scroll or press \\[recenter-top-bottom] to update the numbers." "Delay updates to give Emacs a chance for other changes." :group 'linum :type 'boolean) +(defcustom linum-delay-seconds 0.01 + "Number of seconds to delay before running linum-update-window" + :group 'linum + :type 'floatp) ;;;###autoload (define-minor-mode linum-mode @@ -195,7 +200,12 @@ Linum mode is a buffer-local minor mode." (defun linum-schedule () ;; schedule an update; the delay gives Emacs a chance for display changes - (run-with-idle-timer 0 nil #'linum-update-current)) + (if linum-timer-object + (cancel-timer linum-timer-object)) + (setq linum-timer-object + (run-with-timer linum-delay-seconds + nil + #'linum-update-current))) ;; (defun linum-after-config () ;; (walk-windows (lambda (w) (linum-update (window-buffer w))) nil 'visible)) -- 1.8.3.2