:defer now accepts an optional number of seconds

This commit is contained in:
John Wiegley 2015-03-16 10:46:25 -05:00
parent 302c008b45
commit 1fe2c1c056

View file

@ -373,6 +373,7 @@ possible."
"See docstring for `use-package'." "See docstring for `use-package'."
(let* (let*
((commands (plist-get args :commands)) ((commands (plist-get args :commands))
(deferral (plist-get args :defer))
;; Note: evaluation of this forms possibly extends the value of ;; Note: evaluation of this forms possibly extends the value of
;; `commands'. ;; `commands'.
@ -414,7 +415,7 @@ possible."
;; Should we defer loading of the package lazily? ;; Should we defer loading of the package lazily?
(defer-loading (and (not (plist-get args :demand)) (defer-loading (and (not (plist-get args :demand))
(or commands (plist-get args :defer)))) (or commands deferral)))
;; These are all the configurations to be made after the package has ;; These are all the configurations to be made after the package has
;; loaded. ;; loaded.
@ -450,6 +451,10 @@ possible."
`(autoload #',command ,name-string nil t)) `(autoload #',command ,name-string nil t))
commands))) commands)))
(if (numberp deferral)
`((run-with-idle-timer ,deferral nil
#'require ',name-symbol nil t)))
(when (bound-and-true-p byte-compile-current-file) (when (bound-and-true-p byte-compile-current-file)
(mapcar #'(lambda (fn) (mapcar #'(lambda (fn)
`(declare-function ,fn ,name-string)) `(declare-function ,fn ,name-string))
@ -479,7 +484,7 @@ possible."
,(if use-package-expand-minimally ,(if use-package-expand-minimally
(use-package-progn (use-package-progn
(use-package-cat-maybes (use-package-cat-maybes
(list `(require ',name-symbol nil t)) (list `(require ',name-symbol))
bindings bindings
config-body)) config-body))
`(if (not (require ',name-symbol nil t)) `(if (not (require ',name-symbol nil t))
@ -501,6 +506,9 @@ this file. Usage:
:config Code to run after PACKAGE-NAME has been loaded. Note that if :config Code to run after PACKAGE-NAME has been loaded. Note that if
loading is deferred for any reason, this code does not execute loading is deferred for any reason, this code does not execute
until the lazy load has occurred. until the lazy load has occurred.
:preface Code to be run before everything except `:disabled'; this can
be used to define functions for use in `:if', or that should be
seen by the byte-compiler.
:mode Form to be added to `auto-mode-alist'. :mode Form to be added to `auto-mode-alist'.
:interpreter Form to be added to `interpreter-mode-alist'. :interpreter Form to be added to `interpreter-mode-alist'.
@ -519,6 +527,8 @@ this file. Usage:
:defer Defer loading of a package -- this is implied when using :defer Defer loading of a package -- this is implied when using
`:commands', `:bind', `:bind*', `:mode' or `:interpreter'. `:commands', `:bind', `:bind*', `:mode' or `:interpreter'.
This can be an integer, to force loading after N seconds of
idle time, if the package has not already been loaded.
:demand Prevent deferred loading in all cases. :demand Prevent deferred loading in all cases.
:if EXPR Initialize and load only if EXPR evaluates to a non-nil value. :if EXPR Initialize and load only if EXPR evaluates to a non-nil value.