1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-07 06:50:23 -08:00

Add -hook to the injected hooks

Fixes https://github.com/jwiegley/use-package/issues/161
This commit is contained in:
John Wiegley 2015-03-15 18:49:08 -05:00
parent 03ea5d6dbf
commit 199399e552

View file

@ -77,10 +77,10 @@ then the expanded macros do their job silently."
In particular, for a given package `foo', the following hooks In particular, for a given package `foo', the following hooks
will become available: will become available:
`use-package--foo--pre-init' `use-package--foo--pre-init-hook'
`use-package--foo--post-init' `use-package--foo--post-init-hook'
`use-package--foo--pre-config' `use-package--foo--pre-config-hook'
`use-package--foo--post-config' `use-package--foo--post-config-hook'
This way, you can add to these hooks before evalaution of a This way, you can add to these hooks before evalaution of a
`use-package` declaration, and exercise some control over what `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) (defun use-package-hook-injector (name-string keyword args)
"Wrap pre/post hook injections around a given keyword form." "Wrap pre/post hook injections around a given keyword form."
(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)) (let ((keyword-name (substring (format "%s" keyword) 1))
(block (plist-get args keyword))) (block (plist-get args keyword)))
(when block (when block
`(when ,(use-package-expand name-string (format "pre-%s hook" keyword) `(when ,(use-package-expand name-string (format "pre-%s hook" keyword)
`(run-hook-with-args-until-failure `(run-hook-with-args-until-failure
',(intern (concat "use-package--" name-string ',(intern (concat "use-package--" name-string
"--pre-" keyword-name)))) "--pre-" keyword-name "-hook"))))
,(use-package-expand name-string (format "%s" keyword) ,(use-package-expand name-string (format "%s" keyword)
(plist-get args keyword)) (plist-get args keyword))
,(use-package-expand name-string (format "post-%s hook" keyword) ,(use-package-expand name-string (format "post-%s hook" keyword)
`(run-hooks `(run-hooks
',(intern (concat "use-package--" name-string ',(intern (concat "use-package--" name-string
"--post-" keyword-name)))))))) "--post-" keyword-name "-hook")))))))))
(defmacro use-package-with-elapsed-timer (text &rest body) (defmacro use-package-with-elapsed-timer (text &rest body)
(declare (indent 1)) (declare (indent 1))
@ -377,10 +380,7 @@ the user specified.")
;; loaded. ;; loaded.
(config-body (config-body
(use-package-cat-maybes (use-package-cat-maybes
(list (if use-package-inject-hooks (list (use-package-hook-injector name-string :config args))
(use-package-hook-injector name-string :config args)
(use-package-expand name-string ":config"
(plist-get args :config))))
(mapcar #'(lambda (var) (mapcar #'(lambda (var)
(if (listp var) (if (listp var)
@ -413,10 +413,7 @@ the user specified.")
(append (plist-get args :functions) commands))) (append (plist-get args :functions) commands)))
;; The user's initializations ;; The user's initializations
(list (if use-package-inject-hooks (list (use-package-hook-injector name-string :init args))
(use-package-hook-injector name-string :init args)
(use-package-expand name-string ":init"
(plist-get args :init))))
(if defer-loading (if defer-loading
(use-package-cat-maybes (use-package-cat-maybes