From f30d5761af12836844b2e3e8da11f649a31d8abf Mon Sep 17 00:00:00 2001 From: John Lee Date: Sat, 9 May 2020 19:01:01 +0100 Subject: [PATCH 1/2] Even when there's no :config, run any pre/post config hooks i.e., following the existing docs for use-package-inject-hooks, these hooks are run: use-package--foo--pre-config-hook use-package--foo--post-config-hook This should make config customisations more predictable (for example, spacemacs uses these hooks extensively to allow 'layers' to be customised). I got rid of the "special" default value for :config, because it doesn't seem to be treated any differently than nil. Fixes https://github.com/jwiegley/use-package/issues/785 Copyright-paperwork-exempt: yes --- lisp/use-package/use-package-core.el | 5 ++-- test/lisp/use-package/use-package-tests.el | 30 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/lisp/use-package/use-package-core.el b/lisp/use-package/use-package-core.el index c18877d5e66..f547fcfa5ae 100644 --- a/lisp/use-package/use-package-core.el +++ b/lisp/use-package/use-package-core.el @@ -156,8 +156,7 @@ See also `use-package-defaults', which uses this value." :group 'use-package) (defcustom use-package-defaults - '(;; this '(t) has special meaning; see `use-package-handler/:config' - (:config '(t) t) + '((:config nil t) (:init nil t) (:catch t (lambda (name args) (not use-package-expand-minimally))) @@ -1468,7 +1467,7 @@ no keyword implies `:all'." (use-package-concat (when use-package-compute-statistics `((use-package-statistics-gather :config ',name nil))) - (if (or (null arg) (equal arg '(t))) + (if (and (null arg) (not use-package-inject-hooks)) body (use-package-with-elapsed-timer (format "Configuring package %s" name-symbol) diff --git a/test/lisp/use-package/use-package-tests.el b/test/lisp/use-package/use-package-tests.el index 04a653e30e8..d92a818cdbe 100644 --- a/test/lisp/use-package/use-package-tests.el +++ b/test/lisp/use-package/use-package-tests.el @@ -1474,6 +1474,36 @@ (config) t)))))) +(ert-deftest use-package-test/pre-post-hooks-with-:config () + (let ((use-package-inject-hooks t)) + (match-expansion + (use-package foo :config (config)) + `(progn + (when + (run-hook-with-args-until-failure 'use-package--foo--pre-init-hook) + (run-hooks 'use-package--foo--post-init-hook)) + (require 'foo nil nil) + (when + (run-hook-with-args-until-failure 'use-package--foo--pre-config-hook) + (config) + (run-hooks 'use-package--foo--post-config-hook)) + t)))) + +(ert-deftest use-package-test/pre-post-hooks-without-:config () + ;; https://github.com/jwiegley/use-package/issues/785 + (let ((use-package-inject-hooks t)) + (match-expansion + (use-package foo) + `(progn + (when + (run-hook-with-args-until-failure 'use-package--foo--pre-init-hook) + (run-hooks 'use-package--foo--post-init-hook)) + (require 'foo nil nil) + (when + (run-hook-with-args-until-failure 'use-package--foo--pre-config-hook) + (run-hooks 'use-package--foo--post-config-hook)) + t)))) + (ert-deftest use-package-test-normalize/:diminish () (should (equal (use-package-normalize-diminish 'foopkg :diminish nil) '(foopkg-mode))) From 0ec4660f74e6a182ce8be207f0e9a4cc1a59b9a2 Mon Sep 17 00:00:00 2001 From: John Lee Date: Sat, 9 May 2020 23:35:15 +0100 Subject: [PATCH 2/2] Add special value back again, in case needed for backwards compat I don't know why this special value exists, but perhaps old client code uses it. The additional `t' in the macro expansion is accidental but not harmful I guess. Copyright-paperwork-exempt: yes --- lisp/use-package/use-package-core.el | 5 +++-- test/lisp/use-package/use-package-tests.el | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lisp/use-package/use-package-core.el b/lisp/use-package/use-package-core.el index f547fcfa5ae..220927b082b 100644 --- a/lisp/use-package/use-package-core.el +++ b/lisp/use-package/use-package-core.el @@ -156,7 +156,8 @@ See also `use-package-defaults', which uses this value." :group 'use-package) (defcustom use-package-defaults - '((:config nil t) + '(;; this '(t) has special meaning; see `use-package-handler/:config' + (:config '(t) t) (:init nil t) (:catch t (lambda (name args) (not use-package-expand-minimally))) @@ -1467,7 +1468,7 @@ no keyword implies `:all'." (use-package-concat (when use-package-compute-statistics `((use-package-statistics-gather :config ',name nil))) - (if (and (null arg) (not use-package-inject-hooks)) + (if (and (or (null arg) (equal arg '(t))) (not use-package-inject-hooks)) body (use-package-with-elapsed-timer (format "Configuring package %s" name-symbol) diff --git a/test/lisp/use-package/use-package-tests.el b/test/lisp/use-package/use-package-tests.el index d92a818cdbe..61438185373 100644 --- a/test/lisp/use-package/use-package-tests.el +++ b/test/lisp/use-package/use-package-tests.el @@ -1501,6 +1501,7 @@ (require 'foo nil nil) (when (run-hook-with-args-until-failure 'use-package--foo--pre-config-hook) + t (run-hooks 'use-package--foo--post-config-hook)) t))))