Subject: bug#72993: 31.0.50; 4f521fa14c18f57e5207bffd68e9f79454dccc79 breaks binding mode hooks in use-package

From: Eli Zaretskii <[email-masked]>
Date: Wed, 04 Sep 2024 14:31:27 +0300

> From: John Wiegley <[email-masked]>
> Cc: [email-masked],  [email-masked]
> Date: Tue, 03 Sep 2024 15:35:48 -0700
> 
> >>>>> Eli Zaretskii <[email-masked]> writes:
> 
> >> Perhaps we should avoid auto -hook’ifying the variable name only if the name
> >> does not already end in ‘-functions’?
> 
> > Either that, or maybe exempt FOO-mode from the boundp test.
> 
> This sounds likely to be even better.

Like the below?

diff --git a/lisp/use-package/use-package-core.el b/lisp/use-package/use-package-core.el
index 2c5fc56..6c3d350 100644
--- a/lisp/use-package/use-package-core.el
+++ b/lisp/use-package/use-package-core.el
@@ -1376,13 +1376,16 @@ use-package-handler/:hook
           (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))))