emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/bind-map 5508980148 69/97: Account for multiple declaratio


From: ELPA Syncer
Subject: [nongnu] elpa/bind-map 5508980148 69/97: Account for multiple declarations of the same map
Date: Thu, 20 Jan 2022 07:59:24 -0500 (EST)

branch: elpa/bind-map
commit 5508980148a3146e15da2b3b43b5da2b029875cb
Author: justbur <justin@burkett.cc>
Commit: justbur <justin@burkett.cc>

    Account for multiple declarations of the same map
    
    Specifically, ensure that the major-mode activate variable has just one
    list of associated major modes.
---
 bind-map-tests.el | 13 +++++++++++++
 bind-map.el       | 15 +++++++++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/bind-map-tests.el b/bind-map-tests.el
index bbbd11efce..0974b50df5 100644
--- a/bind-map-tests.el
+++ b/bind-map-tests.el
@@ -73,3 +73,16 @@
     (evil-normalize-keymaps)
     (define-key tmpmap "a" "b")
     (should (string= (key-binding "\C-aa") "b"))))
+
+(ert-deftest bind-map-multiple-declarations ()
+  (let ((tmpmap (make-sparse-keymap))
+        tmpmap-root-map
+        minor-mode-map-alist bind-map-major-modes-alist)
+    (bind-map tmpmap
+      :major-modes (mm1 mm2))
+    (bind-map tmpmap
+      :major-modes (mm3 mm4 mm5))
+    (bind-map tmpmap
+      :major-modes (mm6))
+    (should (equal (cdr (assq 'tmpmap-active bind-map-major-modes-alist))
+                   '(mm1 mm2 mm3 mm4 mm5 mm6)))))
diff --git a/bind-map.el b/bind-map.el
index 4070d68864..a32269c457 100644
--- a/bind-map.el
+++ b/bind-map.el
@@ -153,6 +153,17 @@ when the major mode is an element of the cdr. See
 (add-hook 'change-major-mode-after-body-hook
           'bind-map-change-major-mode-after-body-hook)
 
+(defun bind-map-add-to-major-mode-list (activate-var major-mode-list)
+  "Add (ACTIVATE-VAR . MAJOR-MODE-LIST) to
+`bind-map-major-modes-alist'. If ACTIVATE-VAR is already a key,
+then append MAJOR-MODE-LIST to the existing cdr."
+  (let ((current (assq activate-var bind-map-major-modes-alist)))
+    (if current
+        (setcdr current (append (cdr current)
+                                major-mode-list))
+      (push (cons activate-var major-mode-list)
+            bind-map-major-modes-alist))))
+
 (defun bind-map-kbd-keys (keys)
   "Apply `kbd' to KEYS filtering out nil and empty strings."
   (let (res)
@@ -270,8 +281,8 @@ mode maps. Set up by bind-map.el." map))
      (when major-modes
        ;; compiler warns about making a local var below the top-level
        `((with-no-warnings (defvar-local ,active-var nil))
-         (push (cons ',active-var ,root-map) minor-mode-map-alist)
-         (push (cons ',active-var ',major-modes) bind-map-major-modes-alist)
+         (add-to-list 'minor-mode-map-alist (cons ',active-var ,root-map))
+         (bind-map-add-to-major-mode-list ',active-var ',major-modes)
          ;; call once in case we are already in the relevant major mode
          (bind-map-change-major-mode-after-body-hook)))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]