]> git.eshelyaron.com Git - emacs.git/commitdiff
Add new customization variables `use-package-hook-name-suffix'
authorJohn Wiegley <johnw@newartisans.com>
Mon, 4 Dec 2017 20:04:20 +0000 (12:04 -0800)
committerJohn Wiegley <johnw@newartisans.com>
Mon, 4 Dec 2017 20:04:20 +0000 (12:04 -0800)
Fixes https://github.com/jwiegley/use-package/issues/530

etc/USE-PACKAGE-NEWS
up-core.el
up-tests.el

index b5b5adc0be0891bc3aff435459b2a7fb097f7a28..3bdd623adeb34b5676cc33ba2f056faf3160ed22 100644 (file)
@@ -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
index b4d86971b9bde9e1837cb747a4f2db677b9043cd..fbaa862b06656c9567ec3211ce11de402b8f4f9a 100644 (file)
@@ -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))))))
 
index c1daf0499b9d107fb5a73834f681158303fb0940..dcd3c8d308efd98c3aa1e2fb0f5df8fd8f26c5eb 100644 (file)
          (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