]> git.eshelyaron.com Git - emacs.git/commitdiff
Make byte-compiled uses of `define-minor-mode' more compatible
authorLars Ingebrigtsen <larsi@gnus.org>
Thu, 11 Mar 2021 23:41:50 +0000 (00:41 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Thu, 11 Mar 2021 23:41:54 +0000 (00:41 +0100)
* lisp/emacs-lisp/easy-mmode.el (define-minor-mode): Be more
defensive about accessing minor mode variables.

lisp/emacs-lisp/easy-mmode.el

index 4a9e58083b0e07fc99061722bd7ca7107263aa5b..addb58cdbbe79619d5203568eda7280010b2d148 100644 (file)
@@ -332,12 +332,20 @@ or call the function `%s'."))))
                    t)))
            ;; Keep minor modes list up to date.
            ,@(if globalp
-                 `((setq global-minor-modes (delq ',modefun global-minor-modes))
+                 ;; When running this byte-compiled code in earlier
+                 ;; Emacs versions, these variables may not be defined
+                 ;; there.  So check defensively, even if they're
+                 ;; always defined in Emacs 28 and up.
+                 `((when (boundp 'global-minor-modes)
+                     (setq global-minor-modes
+                           (delq ',modefun global-minor-modes))
+                     (when ,getter
+                       (push ',modefun global-minor-modes))))
+               ;; Ditto check.
+               `((when (boundp 'local-minor-modes)
+                   (setq local-minor-modes (delq ',modefun local-minor-modes))
                    (when ,getter
-                     (push ',modefun global-minor-modes)))
-               `((setq local-minor-modes (delq ',modefun local-minor-modes))
-                 (when ,getter
-                   (push ',modefun local-minor-modes))))
+                     (push ',modefun local-minor-modes)))))
            ,@body
            ;; The on/off hooks are here for backward compatibility only.
            (run-hooks ',hook (if ,getter ',hook-on ',hook-off))