From 4c6fd3c3bdc3d6ee8d03e3fc340156e8a1f97c9e Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Sat, 13 Apr 2024 10:10:19 -0400 Subject: [PATCH] (define-globalized-minor-mode): Fix bug#58888 * lisp/emacs-lisp/easy-mmode.el (define-globalized-minor-mode) : Try and detect well-behaved modes so they're not affected by those which require the cmhh hack. (cherry picked from commit 3f7e26e2bed4ee7adab3a5d2bfa289517499e4c8) --- lisp/emacs-lisp/easy-mmode.el | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el index 095bd5faa03..b09466d79fc 100644 --- a/lisp/emacs-lisp/easy-mmode.el +++ b/lisp/emacs-lisp/easy-mmode.el @@ -661,8 +661,12 @@ list." ;; The function that catches kill-all-local-variables. (defun ,MODE-cmhh () - (add-to-list ',MODE-buffers (current-buffer)) - (add-hook 'post-command-hook #',MODE-check-buffers)) + ;; If `delay-mode-hooks' is set, it indicates that the current + ;; buffer's mode will run `run-mode-hooks' afterwards anyway, + ;; so we don't need to keep this buffer in MODE-buffers. + (unless delay-mode-hooks + (add-to-list ',MODE-buffers (current-buffer)) + (add-hook 'post-command-hook #',MODE-check-buffers))) (put ',MODE-cmhh 'definition-name ',global-mode)))) (defun easy-mmode--globalized-predicate-p (predicate) -- 2.39.5