From 057814ae241e44f7550e5d485decb6f40e312d3c Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 4 Dec 2017 12:04:20 -0800 Subject: [PATCH] Add new customization variables `use-package-hook-name-suffix' Fixes https://github.com/jwiegley/use-package/issues/530 --- etc/USE-PACKAGE-NEWS | 2 ++ up-core.el | 14 ++++++++++++-- up-tests.el | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/etc/USE-PACKAGE-NEWS b/etc/USE-PACKAGE-NEWS index b5b5adc0be0..3bdd623adeb 100644 --- a/etc/USE-PACKAGE-NEWS +++ b/etc/USE-PACKAGE-NEWS @@ -66,6 +66,8 @@ - New customization variable `use-package-enable-imenu-support`. +- New customization variable `use-package-hook-name-suffix`. + - Allow `:diminish` to take no arguments. - Support multiple symbols passed to `:after`, and a mini-DSL using `:all` and diff --git a/up-core.el b/up-core.el index b4d86971b9b..fbaa862b066 100644 --- a/up-core.el +++ b/up-core.el @@ -180,6 +180,13 @@ be attempted." (choice :tag "Enable if non-nil" sexp function))) :group 'use-package) +(defcustom use-package-hook-name-suffix "-hook" + "Text append to the name of hooks mentioned by :hook. +Set to `nil' if you don't want this to happen; it's only a +convenience." + :type '(choice string (const :tag "No suffix" nil)) + :group 'use-package) + (defcustom use-package-minimum-reported-time 0.1 "Minimal load time that will be reported. Note that `use-package-verbose' has to be set to a non-nil value @@ -1136,8 +1143,11 @@ deferred until the prefix key sequence is pressed." (when fun (mapcar #'(lambda (sym) - `(add-hook (quote ,(intern (format "%s-hook" sym))) - (function ,fun))) + `(add-hook + (quote ,(intern + (concat (symbol-name sym) + use-package-hook-name-suffix))) + (function ,fun))) (if (use-package-non-nil-symbolp syms) (list syms) syms))))) nargs)))))) diff --git a/up-tests.el b/up-tests.el index c1daf0499b9..dcd3c8d308e 100644 --- a/up-tests.el +++ b/up-tests.el @@ -891,6 +891,38 @@ (ignore (bind-keys :package foo ("C-a" . key)))))))) +(ert-deftest use-package-test/:hook-2 () + (match-expansion + (use-package foo + :hook (hook . fun)) + `(progn + (unless (fboundp 'fun) + (autoload #'fun "foo" nil t)) + (ignore + (add-hook 'hook-hook #'fun))))) + +(ert-deftest use-package-test/:hook-3 () + (let ((use-package-hook-name-suffix nil)) + (match-expansion + (use-package foo + :hook (hook . fun)) + `(progn + (unless (fboundp 'fun) + (autoload #'fun "foo" nil t)) + (ignore + (add-hook 'hook #'fun)))))) + +(ert-deftest use-package-test/:hook-4 () + (let ((use-package-hook-name-suffix "-special")) + (match-expansion + (use-package foo + :hook (hook . fun)) + `(progn + (unless (fboundp 'fun) + (autoload #'fun "foo" nil t)) + (ignore + (add-hook 'hook-special #'fun)))))) + (ert-deftest use-package-test-normalize/:custom () (flet ((norm (&rest args) (apply #'use-package-normalize/:custom -- 2.39.2