From 9385ab417af21653b5b62219dd19ac95a0df3b0a Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sun, 15 Mar 2015 18:07:37 -0500 Subject: [PATCH] BREAKING CHANGE: Remove :idle and :idle-priority I am removing this feature for now because it can result in a nasty inconsistency. Consider the following definition: (use-package vkill :commands vkill :idle (some-important-configuration-here) :bind ("C-x L" . vkill-and-helm-occur) :init (defun vkill-and-helm-occur () (interactive) (vkill) (call-interactively #'helm-occur)) :config (setq vkill-show-all-processes t)) If I load my Emacs and wait until the idle timer fires, then this is the sequence of events: :init :idle :config But if I load Emacs and immediately type C-x L without waiting for the idle timer to fire, this is the sequence of events: :init :config :idle It's possible that the user could use `featurep` in their idle to test for this case, but that's a subtlety I'd rather avoid. What I would consider is this: `:idle [N]` is a keyword that simply implies `:defer`, with an option number of N to specify a second count. After that many seconds, if the package has not yet been loaded by autoloading, it will be loaded via the idle timer. This approach has the benefit of complete consistency for both the idle and the autoloaded cases. Although, the fact that it implies `:defer` means we don't have to consider what it means to add `:idle` behavior to a demand-loaded configuration. --- lisp/use-package/use-package.el | 102 +++----------------------------- 1 file changed, 9 insertions(+), 93 deletions(-) diff --git a/lisp/use-package/use-package.el b/lisp/use-package/use-package.el index e4ef0048e59..ce96a701ebc 100644 --- a/lisp/use-package/use-package.el +++ b/lisp/use-package/use-package.el @@ -294,19 +294,9 @@ the user specified.") (use-package-as-one (symbol-name head) args (apply-partially #'use-package-normalize-diminish name-symbol))) - ((or :preface :init :config :idle) + ((or :preface :init :config) (use-package-normalize-form (symbol-name head) args)) - (:idle-priority - (if (null args) - 5 - (use-package-only-one (symbol-name head) args - (lambda (label arg) - (if (numberp arg) - arg - (use-package-error - ":idle-priority wants an optional number")))))) - (:load-path (use-package-as-one (symbol-name head) args #'use-package-normalize-paths)) @@ -408,8 +398,14 @@ the user specified.") ;; Setup any required autoloads (if defer-loading - (mapcar #'(lambda (command) `(autoload #',command ,name-string nil t)) - commands)) + (delete nil + (mapcar #'(lambda (command) + ;; (unless (and (fboundp command) + ;; (not (autoloadp command))) + ;; `(autoload #',command ,name-string nil t)) + `(autoload #',command ,name-string nil t) + ) + commands))) (when (bound-and-true-p byte-compile-current-file) (mapcar #'(lambda (fn) @@ -442,14 +438,6 @@ the user specified.") config-body) t)))) - ;; Any :idle form that should be executed later - (let ((idle-body (plist-get args :idle))) - (when idle-body - `((require 'use-package) - (use-package-init-on-idle - #'(lambda () ,(use-package-expand name-string ":idle" idle-body)) - ,(plist-get args :idle-priority))))) - (list t)))) (defmacro use-package (name &rest args) @@ -491,10 +479,6 @@ this file. Usage: :functions Declare certain functions to silence the byte-compiler. :load-path Add to the `load-path' before attempting to load the package. :diminish Support for diminish.el (if installed). -:idle Adds a form to be run on an idle timer after initialization. -:idle-priority Schedules the :idle form to run with the given priority (lower - priorities run first). Default priority is 5; forms with the - same priority are run in the order in which they are evaluated. :ensure Loads the package using package.el if necessary. :pin Pin the package to an archive." (declare (indent 1)) @@ -594,74 +578,6 @@ deferred until the prefix key sequence is pressed." (font-lock-add-keywords 'emacs-lisp-mode use-package-font-lock-keywords) -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; -;; :idle support -;; - -(defcustom use-package-idle-interval 3 - "Time to wait when using :idle in a `use-package' specification." - :type 'number - :group 'use-package) - -(defvar use-package-idle-timer nil) -(defvar use-package-idle-forms (make-hash-table)) - -(defun use-package-start-idle-timer () - "Ensure that the idle timer is running." - (unless use-package-idle-timer - (setq use-package-idle-timer - (run-with-idle-timer use-package-idle-interval t - 'use-package-idle-eval)))) - -(defun use-package-init-on-idle (form priority) - "Add a new form to the idle queue." - (use-package-start-idle-timer) - (puthash priority - (append (gethash priority use-package-idle-forms) - (list form)) - use-package-idle-forms)) - -(defun use-package-idle-priorities () - "Get a list of all priorities in the idle queue. -The list is sorted in the order forms should be run." - (let ((priorities nil)) - (maphash #'(lambda (priority forms) - (setq priorities (cons priority priorities))) - use-package-idle-forms) - (sort priorities '<))) - -(defun use-package-idle-pop () - "Pop the top-priority task from the idle queue. -Return nil when the queue is empty." - (let* ((priority (car (use-package-idle-priorities))) - (forms (gethash priority use-package-idle-forms)) - (first-form (car forms)) - (forms-remaining (cdr forms))) - (if forms-remaining - (puthash priority forms-remaining use-package-idle-forms) - (remhash priority use-package-idle-forms)) - first-form)) - -(defun use-package-idle-eval () - "Start to eval idle-commands from the idle queue." - (let ((next (use-package-idle-pop))) - (if next - (progn - (when use-package-verbose - (message "use-package idle: %s" next)) - (condition-case e - (funcall next) - (error - (error "Failure on use-package idle. Form: %s, Error: %s" - next e))) - ;; recurse after a bit - (when (sit-for use-package-idle-interval) - (use-package-idle-eval))) - ;; finished (so far!) - (cancel-timer use-package-idle-timer) - (setq use-package-idle-timer nil)))) - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; :pin and :ensure support -- 2.39.2