aboutsummaryrefslogtreecommitdiff
path: root/lisp/later-do.el
diff options
context:
space:
mode:
authorPierre Neidhardt <ambrevar@gmail.com>2018-04-07 18:53:43 +0530
committerPierre Neidhardt <ambrevar@gmail.com>2018-04-09 12:33:43 +0530
commit122a8b375b4f5f90de3b41e766442d23c5b2b524 (patch)
treea1e0eaa6430d3aaa5e2e0c1f5af007e1701f47cb /lisp/later-do.el
parent283c04e54c080b55f7d044b7eaa54f29356e97da (diff)
* lisp/later-do.el: Speed up later-do-list job by batch-processing
A `later-do-batch' defcustom was introduced to allow for performance tweaking.
Diffstat (limited to 'lisp/later-do.el')
-rw-r--r--lisp/later-do.el28
1 files changed, 19 insertions, 9 deletions
diff --git a/lisp/later-do.el b/lisp/later-do.el
index d8222ae..5908ac5 100644
--- a/lisp/later-do.el
+++ b/lisp/later-do.el
@@ -1,7 +1,7 @@
;;; later-do.el --- execute lisp code ... later
;; Copyright (C) 2004, 2005, 2006, 2007, 2008,
-;; 2009 Free Software Foundation, Inc.
+;; 2009, 2018 Free Software Foundation, Inc.
;; Author: Jorgen Schaefer <forcer@forcix.cx>
@@ -28,7 +28,7 @@
;;; Code:
-(defvar later-do-version "0.2emms2 (2005-09-20)"
+(defvar later-do-version "0.2emms4 (2018-04-07)"
"Version string of later-do.")
(defgroup later-do nil
@@ -41,6 +41,14 @@
:group 'later-do
:type 'number)
+(defcustom later-do-batch 20
+ "How many functions to process before waiting `later-do-interval'.
+The functions are processed from `later-do-list'. Must be 1 or
+greater. Too high a value might make Emacs slower while the
+list is being processed."
+ :group 'later-do
+ :type 'number)
+
(defvar later-do-list nil
"A list of functions to be called later on.")
@@ -63,14 +71,16 @@ executed in the sequence it was added."
empty."
(if (null later-do-list)
(setq later-do-timer nil)
- (let ((fun (caar later-do-list))
- (args (cdar later-do-list)))
- (setq later-do-list (cdr later-do-list))
+ (let (res)
(unwind-protect
- (apply fun args)
- (setq later-do-timer (run-with-timer later-do-interval
- nil
- 'later-do-timer))))))
+ (dotimes (b (min later-do-batch (length later-do-list)) res)
+ (let ((fun (caar later-do-list))
+ (args (cdar later-do-list)))
+ (setq later-do-list (cdr later-do-list))
+ (setq res (apply fun args)))))
+ (setq later-do-timer (run-with-timer later-do-interval
+ nil
+ 'later-do-timer)))))
(provide 'later-do)
;;; later-do.el ends here