[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/bind-map 9a676378fe 54/97: Simplify major-mode activation
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/bind-map 9a676378fe 54/97: Simplify major-mode activation |
Date: |
Thu, 20 Jan 2022 07:59:20 -0500 (EST) |
branch: elpa/bind-map
commit 9a676378fe2c4e4be602f0b5e77330e28cba6cbd
Author: justbur <justin@burkett.cc>
Commit: justbur <justin@burkett.cc>
Simplify major-mode activation
Instead of creating a new activation function for each map, use one
centralized activation function that processes a list of vars
corresponding to a map and the major-modes in which that map should be
active.
Reduces the number of functions and variables generated by bind-map
---
bind-map.el | 33 ++++++++++++++++++++-------------
1 file changed, 20 insertions(+), 13 deletions(-)
diff --git a/bind-map.el b/bind-map.el
index a6b5db9b11..b549048561 100644
--- a/bind-map.el
+++ b/bind-map.el
@@ -136,6 +136,21 @@ be activated.")
(define-key (symbol-value map) (nth 2 entry) (nth 3 entry))))))
(add-hook 'evil-local-mode-hook 'bind-map-evil-local-mode-hook)
+(defvar bind-map-major-modes-alist '()
+ "Each element takes the form (MAP-ACTIVE (MAJOR-MODE1
+MAJOR-MODE2 ...)). The car is the variable used to activate a map
+when the major mode is an element of the cdr. See
+`bind-map-change-major-mode-after-body-hook'.")
+
+(defun bind-map-change-major-mode-after-body-hook ()
+ "Called to activate major mode maps in a buffer."
+ ;; format is (ACTIVATE-VAR MAJOR-MODES-LIST)
+ (dolist (entry bind-map-major-modes-alist)
+ (setf (symbol-value (car entry))
+ (not (null (member major-mode (cdr entry)))))))
+(add-hook 'change-major-mode-after-body-hook
+ 'bind-map-change-major-mode-after-body-hook)
+
;;;###autoload
(defmacro bind-map (map &rest args)
"Bind keymap MAP in multiple locations.
@@ -205,9 +220,7 @@ unspecified the bindings are global.
Declare a prefix command for MAP named COMMAND-NAME."
(let* ((root-map (intern (format "%s-root-map" map)))
- (major-mode-list (intern (format "%s-major-modes" map)))
- (activate (intern (format "%s-activate" map)))
- (activate-func (intern (format "%s-activate-function" map)))
+ (active-var (intern (format "%s-active" map)))
(prefix-cmd (or (plist-get args :prefix-cmd)
(intern (format "%s-prefix" map))))
(keys (plist-get args :keys))
@@ -243,18 +256,12 @@ mode maps. Set up by bind-map.el." map))
(push (cons mode ,root-map) minor-mode-map-alist)))
(when ',major-modes
- (defvar ,major-mode-list '())
;; compiler warns about making a local var below the top-level
- (with-no-warnings
- (defvar-local ,activate nil))
- (push (cons ',activate ,root-map) minor-mode-map-alist)
- (dolist (mode ',major-modes)
- (add-to-list ',major-mode-list mode))
- (defun ,activate-func ()
- (setq ,activate (not (null (member major-mode ,major-mode-list)))))
+ (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)
;; call once in case we are already in the relevant major mode
- (,activate-func)
- (add-hook 'change-major-mode-after-body-hook ',activate-func))
+ (bind-map-change-major-mode-after-body-hook))
(when (and ,override-minor-modes
(null ',major-modes)
- [nongnu] elpa/bind-map 5c6f17939c 28/97: Get rid of eval-after-loads to fix evil bindings, (continued)
- [nongnu] elpa/bind-map 5c6f17939c 28/97: Get rid of eval-after-loads to fix evil bindings, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map 80c38c4052 61/97: Add badges, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map 4cccf8fb82 23/97: Add configuration var for default map suffix, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map 7a4d329a60 18/97: Correct wrong package names, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map 4cf9dfd1cb 81/97: Fix declare form, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map ddce68ed1d 53/97: Move evil-local-mode hook next to var, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map 2a5fcbd947 73/97: Revert "Fix incorrect check of override mode in local hook", ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map f4fad049d0 70/97: Bump to version 1.0, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map 9599acb5ab 35/97: Silence warning about defvar-local, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map 662dea907c 51/97: Suppress make-local warnings from compiler, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map 9a676378fe 54/97: Simplify major-mode activation,
ELPA Syncer <=
- [nongnu] elpa/bind-map e239bbdaef 44/97: Always use global evil maps, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map af26966c9a 57/97: Make macro expansion prettier, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map 393879d260 58/97: Satisfy compiler, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map 2fafc10f7d 45/97: Rename a var and a function and tweak a docstring, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map e94572b50b 74/97: Increment version, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map 00b7778826 68/97: Fix minor-mode tests, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map 9ae3e9b113 72/97: Increment version, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map 40ed95d4d5 80/97: Add bindings keyword, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map 6f84c0254f 78/97: Increment version, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map c335674139 60/97: Add files for travis, ELPA Syncer, 2022/01/20