Subject: Re: bug#79305: 31.0.50; MODE-set-explicitly change caused regressions in bind-map

From: Stefan Monnier <[email-masked]>
Date: Mon, 01 Sep 2025 00:49:48 -0400

>> bind-map shouldn't use an internal variable like that.
> +1, tho maybe bind-map has a good reason to do that.
> Does anyone know something about that?

After spending some time looking at the code, its history, and the
corresponding doc, my conclusion is that `bind-map`s code was probably
incorrect already with older Emacsen (just in different ways) and its
intended behavior is far from clear, so I think it's best to leave this
as a WONTFIX and let `bind-map`s authors figure out what to do on
their side (tho I'd be happy to help them figure that out).

The best patch I could come up with is the one below.

        Stefan

diff --git a/bind-map.el b/bind-map.el
index 41e6e5b5f0..204748efe8 100644
--- a/bind-map.el
+++ b/bind-map.el
@@ -171,19 +171,17 @@ be activated.")
          (when properties (pop properties)))))
 
 (defun bind-map-evil-local-mode-hook ()
-  "Called to activate local state maps in a buffer."
+  "Activate local state maps in a buffer." ;; FIXME: Which buffer?
   ;; format is (OVERRIDE-MODE STATE KEY DEF)
   (dolist (entry bind-map-evil-local-bindings)
     (let* ((map (intern (format "evil-%s-state-local-map" (nth 1 entry))))
            (mode (nth 0 entry))
-           (global-mode (intern (format "global-%s" (nth 0 entry))))
-           (set-explicitly (intern (format "%s-set-explicitly" mode))))
-      (when (and (boundp global-mode) (boundp mode)
-                 (boundp set-explicitly) (boundp map)
+           ;; FIXME: Why do we care about an associated global mode?
+           (global-mode (intern (format "global-%s" mode))))
+      (when (and (boundp global-mode) (boundp mode) (boundp map)
                  (keymapp (symbol-value map))
                  (symbol-value global-mode)
-                 (not (and (symbol-value set-explicitly)
-                           (null (symbol-value mode)))))
+                 (symbol-value mode))
         (define-key (symbol-value map) (nth 2 entry) (nth 3 entry))))))
 (add-hook 'evil-local-mode-hook 'bind-map-evil-local-mode-hook)