summaryrefslogtreecommitdiff
path: root/lisp/use-package/use-package.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/use-package/use-package.el')
-rw-r--r--lisp/use-package/use-package.el149
1 files changed, 31 insertions, 118 deletions
diff --git a/lisp/use-package/use-package.el b/lisp/use-package/use-package.el
index 36021b4d520..17543e3e734 100644
--- a/lisp/use-package/use-package.el
+++ b/lisp/use-package/use-package.el
@@ -77,10 +77,10 @@ then the expanded macros do their job silently."
In particular, for a given package `foo', the following hooks
will become available:
- `use-package--foo--pre-init'
- `use-package--foo--post-init'
- `use-package--foo--pre-config'
- `use-package--foo--post-config'
+ `use-package--foo--pre-init-hook'
+ `use-package--foo--post-init-hook'
+ `use-package--foo--pre-config-hook'
+ `use-package--foo--post-config-hook'
This way, you can add to these hooks before evalaution of a
`use-package` declaration, and exercise some control over what
@@ -93,19 +93,22 @@ the user specified.")
(defun use-package-hook-injector (name-string keyword args)
"Wrap pre/post hook injections around a given keyword form."
- (let ((keyword-name (substring (format "%s" keyword) 1))
- (block (plist-get args keyword)))
- (when block
- `(when ,(use-package-expand name-string (format "pre-%s hook" keyword)
- `(run-hook-with-args-until-failure
- ',(intern (concat "use-package--" name-string
- "--pre-" keyword-name))))
- ,(use-package-expand name-string (format "%s" keyword)
- (plist-get args keyword))
- ,(use-package-expand name-string (format "post-%s hook" keyword)
- `(run-hooks
- ',(intern (concat "use-package--" name-string
- "--post-" keyword-name))))))))
+ (if (not use-package-inject-hooks)
+ (use-package-expand name-string (format "%s" keyword)
+ (plist-get args keyword))
+ (let ((keyword-name (substring (format "%s" keyword) 1))
+ (block (plist-get args keyword)))
+ (when block
+ `(when ,(use-package-expand name-string (format "pre-%s hook" keyword)
+ `(run-hook-with-args-until-failure
+ ',(intern (concat "use-package--" name-string
+ "--pre-" keyword-name "-hook"))))
+ ,(use-package-expand name-string (format "%s" keyword)
+ (plist-get args keyword))
+ ,(use-package-expand name-string (format "post-%s hook" keyword)
+ `(run-hooks
+ ',(intern (concat "use-package--" name-string
+ "--post-" keyword-name "-hook")))))))))
(defmacro use-package-with-elapsed-timer (text &rest body)
(declare (indent 1))
@@ -294,19 +297,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))
@@ -387,10 +380,7 @@ the user specified.")
;; loaded.
(config-body
(use-package-cat-maybes
- (list (if use-package-inject-hooks
- (use-package-hook-injector name-string :config args)
- (use-package-expand name-string ":config"
- (plist-get args :config))))
+ (list (use-package-hook-injector name-string :config args))
(mapcar #'(lambda (var)
(if (listp var)
@@ -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)
@@ -417,10 +413,7 @@ the user specified.")
(append (plist-get args :functions) commands)))
;; The user's initializations
- (list (if use-package-inject-hooks
- (use-package-hook-injector name-string :init args)
- (use-package-expand name-string ":init"
- (plist-get args :init))))
+ (list (use-package-hook-injector name-string :init args))
(if defer-loading
(use-package-cat-maybes
@@ -442,14 +435,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 +476,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))
@@ -596,74 +577,6 @@ deferred until the prefix key sequence is pressed."
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
-;; :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
;;