diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el index 095bd5faa03..015ab1d3f84 100644 --- a/lisp/emacs-lisp/easy-mmode.el +++ b/lisp/emacs-lisp/easy-mmode.el @@ -661,8 +661,12 @@ define-globalized-minor-mode ;; 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 BUF 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)