Fix :hook in 'use-package'
authorEli Zaretskii <eliz@gnu.org>
Wed, 4 Sep 2024 17:43:25 +0000 (20:43 +0300)
committerEli Zaretskii <eliz@gnu.org>
Wed, 4 Sep 2024 17:43:25 +0000 (20:43 +0300)
* lisp/use-package/use-package-core.el
(use-package-handler/:hook): Support mode variables in :hook
declarations.  (Bug#72993)

lisp/use-package/use-package-core.el

index 2c5fc560749058bacecea6a5e486613ef03559ce..6c3d350c610c2fa9976bfca5a1c2b52497df1195 100644 (file)
@@ -1376,13 +1376,16 @@ enable gathering statistics."
           (when fun
             (mapcar
              #'(lambda (sym)
-                 (if (boundp sym)
-                     `(add-hook (quote ,sym) (function ,fun))
-                   `(add-hook
-                     (quote ,(intern
-                              (concat (symbol-name sym)
-                                      use-package-hook-name-suffix)))
-                     (function ,fun))))
+                 (let ((symname (symbol-name sym)))
+                   (if (and (boundp sym)
+                            ;; Mode variables are usually bound, but
+                            ;; their hooks are named FOO-mode-hook.
+                            (not (string-suffix-p "-mode" symname)))
+                       `(add-hook (quote ,sym) (function ,fun))
+                     `(add-hook
+                       (quote ,(intern
+                                (concat symname use-package-hook-name-suffix)))
+                       (function ,fun)))))
              (use-package-hook-handler-normalize-mode-symbols syms)))))
     (use-package-normalize-commands args))))