aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2025-10-14 11:21:29 -0400
committerStefan Monnier2025-10-14 11:47:05 -0400
commit171c7fd6df861ab71f6cc8faedb8ff68bfac4bae (patch)
tree7bef470688a7ae75962948886bd51ec8f3a2795e
parent3aae55acfc5b43ebe436dfc57937db217ccc0891 (diff)
downloademacs-171c7fd6df861ab71f6cc8faedb8ff68bfac4bae.tar.gz
emacs-171c7fd6df861ab71f6cc8faedb8ff68bfac4bae.zip
(define-minor-mode): Update `global-minor-modes` if init-value is non-nil
When a global minor mode is enabled by init-value rather than by calling the major mode function, we failed to register it in `global-minor-modes` (bug#79518). * lisp/emacs-lisp/easy-mmode.el (define-minor-mode): Register ourselves in `global-minor-modes` at top-level for global modes with a non-nil init-value. Also in the `modefun`, simply the code with `not` and `add-to-list` and consolidate the local/global paths to update `*-minor-modes`. * lisp/simple.el (global-minor-modes): Move to... * lisp/subr.el (global-minor-modes): ...here so it's defined early enough for `auto-compression-mode` to register itself.
-rw-r--r--lisp/emacs-lisp/easy-mmode.el53
-rw-r--r--lisp/simple.el4
-rw-r--r--lisp/subr.el4
3 files changed, 28 insertions, 33 deletions
diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el
index 25e4f882295..0aa1fe2ce9d 100644
--- a/lisp/emacs-lisp/easy-mmode.el
+++ b/lisp/emacs-lisp/easy-mmode.el
@@ -332,12 +332,16 @@ for a description of this minor mode."
332Setting this variable directly does not take effect; 332Setting this variable directly does not take effect;
333either customize it (see the info node `Easy Customization') 333either customize it (see the info node `Easy Customization')
334or call the function `%s'.")))) 334or call the function `%s'."))))
335 `(defcustom ,mode ,init-value 335 `(progn
336 ,(format base-doc-string pretty-name mode mode) 336 (defcustom ,mode ,init-value
337 ,@set 337 ,(format base-doc-string pretty-name mode mode)
338 ,@initialize 338 ,@set
339 ,@type 339 ,@initialize
340 ,@(nreverse extra-keywords))))) 340 ,@type
341 ,@(nreverse extra-keywords))
342 ,(when init-value
343 `(when (bound-and-true-p ,mode)
344 (add-to-list 'global-minor-modes ',modefun)))))))
341 345
342 ;; The actual function. 346 ;; The actual function.
343 ,(funcall 347 ,(funcall
@@ -360,30 +364,21 @@ or call the function `%s'."))))
360 'toggle))))) 364 'toggle)))))
361 (let ((,last-message (current-message))) 365 (let ((,last-message (current-message)))
362 (,@setter 366 (,@setter
363 (cond ((eq arg 'toggle) 367 (cond ((eq arg 'toggle) (not ,getter))
364 (not ,getter)) 368 (t (not (and (numberp arg) (< arg 1))))))
365 ((and (numberp arg)
366 (< arg 1))
367 nil)
368 (t
369 t)))
370 ;; Keep minor modes list up to date. 369 ;; Keep minor modes list up to date.
371 ,@(if globalp 370 ,(let ((minor-modes-var (if globalp
372 ;; When running this byte-compiled code in earlier 371 'global-minor-modes
373 ;; Emacs versions, these variables may not be defined 372 'local-minor-modes)))
374 ;; there. So check defensively, even if they're 373 ;; When running this byte-compiled code in earlier
375 ;; always defined in Emacs 28 and up. 374 ;; Emacs versions, these variables may not be defined
376 `((when (boundp 'global-minor-modes) 375 ;; there. So check defensively, even if they're
377 (setq global-minor-modes 376 ;; always defined in Emacs 28 and up.
378 (delq ',modefun global-minor-modes)) 377 `(when (boundp ',minor-modes-var)
379 (when ,getter 378 (if ,getter
380 (push ',modefun global-minor-modes)))) 379 (add-to-list ',minor-modes-var ',modefun)
381 ;; Ditto check. 380 (setq ,minor-modes-var
382 `((when (boundp 'local-minor-modes) 381 (delq ',modefun ,minor-modes-var)))))
383 (setq local-minor-modes
384 (delq ',modefun local-minor-modes))
385 (when ,getter
386 (push ',modefun local-minor-modes)))))
387 ,@body 382 ,@body
388 ;; The on/off hooks are here for backward compatibility only. 383 ;; The on/off hooks are here for backward compatibility only.
389 (run-hooks ',hook (if ,getter ',hook-on ',hook-off)) 384 (run-hooks ',hook (if ,getter ',hook-on ',hook-off))
diff --git a/lisp/simple.el b/lisp/simple.el
index 824f7c5a1a0..589b136a008 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -157,10 +157,6 @@ messages are highlighted; this helps to see what messages were visited."
157 nil 157 nil
158 "Overlay highlighting the current error message in the `next-error' buffer.") 158 "Overlay highlighting the current error message in the `next-error' buffer.")
159 159
160(defvar global-minor-modes nil
161 "A list of the currently enabled global minor modes.
162This is a list of symbols.")
163
164(defcustom next-error-hook nil 160(defcustom next-error-hook nil
165 "List of hook functions run by `next-error' after visiting source file." 161 "List of hook functions run by `next-error' after visiting source file."
166 :type 'hook 162 :type 'hook
diff --git a/lisp/subr.el b/lisp/subr.el
index 9f1680f3896..891663f7640 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -3064,6 +3064,10 @@ though trying to avoid AVOIDED-MODES."
3064 hs-minor-mode) 3064 hs-minor-mode)
3065 "List of all minor mode functions.") 3065 "List of all minor mode functions.")
3066 3066
3067(defvar global-minor-modes nil
3068 "A list of the currently enabled global minor modes.
3069This is a list of symbols.")
3070
3067(defun add-minor-mode (toggle name &optional keymap after toggle-fun) 3071(defun add-minor-mode (toggle name &optional keymap after toggle-fun)
3068 "Register a new minor mode. 3072 "Register a new minor mode.
3069 3073