[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/bind-map d45971cd40 46/97: Use minor mode for overriding b
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/bind-map d45971cd40 46/97: Use minor mode for overriding behavior |
Date: |
Thu, 20 Jan 2022 07:59:18 -0500 (EST) |
branch: elpa/bind-map
commit d45971cd402df5edb7c24b97a3ca6a978a95243b
Author: justbur <justin@burkett.cc>
Commit: justbur <justin@burkett.cc>
Use minor mode for overriding behavior
1. evil-use-local is deprecated. It has the same effect as
:override-minor-modes (they provided very similar functionality to begin
with)
2. Specifying :override-minor-modes now defines a very simple minor mode
which has the default name MAP-overriding-mode (can be changed using
:override-mode-name). This minor mode toggles the overriding behavior of
both :keys and :evil-keys. It's defined as a globalized-minor-mode, is
activated by default, and is never activated in the minibuffer. The
functionality provided does not change.
---
bind-map.el | 72 +++++++++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 53 insertions(+), 19 deletions(-)
diff --git a/bind-map.el b/bind-map.el
index 588ce8add8..43b1e2ba50 100644
--- a/bind-map.el
+++ b/bind-map.el
@@ -117,8 +117,10 @@
:group 'bind-map)
(defvar bind-map-evil-local-bindings '()
- "Each element of this list takes the form (STATE KEY DEF) and
-corresponds to a binding for an evil local state map.")
+ "Each element of this list takes the form (OVERRIDE-MODE STATE
+KEY DEF) and corresponds to a binding for an evil local state
+map. OVERRIDE-MODE is the minor mode that must be enabled for
+these to be activated.")
(defvaralias 'bind-map-local-bindings 'bind-map-evil-local-bindings)
(make-obsolete-variable 'bind-map-local-bindings
'bind-map-evil-local-bindings "2015-12-2")
@@ -143,10 +145,23 @@ suitable for use in `kbd'.
:override-minor-modes BOOL
If non nil, make keys in :keys override the minor-mode maps, by
-using `emulation-mode-map-alists' instead of the `global-map'. If
+using `emulation-mode-map-alists' instead of the `global-map'.
+This is done for the :evil-keys using evil local state maps. If
either :major-modes or :minor-modes is specified, this setting
has no effect.
+The overriding behavior can be toggled using the minor mode
+MAP-overriding-mode (the name of the minor mode can be customized
+in the next keyword). It is enabled by default when you specify
+this keyword.
+
+:override-mode-name SYMBOL
+
+The name to use for the minor mode described for the previous
+keyword (a default name will be given if this is left
+unspeficied). This setting as no effect if :override-minor-modes
+is nil or unspecified.
+
:evil-keys (KEY1 KEY2 ...)
Like :keys but these bindings are only active in certain evil
@@ -159,11 +174,9 @@ use `bind-map-default-evil-states'.
:evil-use-local BOOL
-This places all evil bindings in the local state maps for
-evil (in addition to the global ones). These maps have high
-precedence and will mask most other evil bindings. If
-either :major-modes or :minor-modes is specified, this setting
-has no effect.
+(Deprecated) This is now equivalent to setting
+`:override-minor-modes' to t, which handles evil and non-evil
+keys now.
:major-modes (MODE1 MODE2 ...)
@@ -187,11 +200,20 @@ Declare a prefix command for MAP named COMMAND-NAME."
(prefix-cmd (or (plist-get args :prefix-cmd)
(intern (format "%s-prefix" map))))
(keys (plist-get args :keys))
- (override-minor-modes (plist-get args :override-minor-modes))
+ (override-minor-modes (or (plist-get args :override-minor-modes)
+ (plist-get args :evil-use-local)))
+ (override-mode (if (plist-get args :override-mode-name)
+ (plist-get args :override-mode-name)
+ (intern (format "%s-override-mode" map))))
+ (override-mode-doc (format "Minor mode that makes %s override minor \
+mode maps. Set up by bind-map.el." override-mode))
+ (global-override-mode (intern (format "global-%s" override-mode)))
+ (turn-on-override-mode (intern (format "turn-on-%s" override-mode)))
+ (turn-on-override-mode-doc (format "Enable `%s' except in minibuffer"
+ override-mode))
(evil-keys (plist-get args :evil-keys))
(evil-states (or (plist-get args :evil-states)
bind-map-default-evil-states))
- (evil-use-local (plist-get args :evil-use-local))
(minor-modes (plist-get args :minor-modes))
(major-modes (plist-get args :major-modes)))
`(progn
@@ -224,7 +246,16 @@ Declare a prefix command for MAP named COMMAND-NAME."
(when (and ,override-minor-modes
(null ',major-modes)
(null ',minor-modes))
- (add-to-list 'emulation-mode-map-alists (list (cons t ,root-map))))
+ (defun ,turn-on-override-mode ()
+ ,turn-on-override-mode-doc
+ (unless (minibufferp) (,override-mode 1)))
+ (define-globalized-minor-mode ,global-override-mode
+ ,override-mode ,turn-on-override-mode)
+ (define-minor-mode ,override-mode
+ ,override-mode-doc)
+ (add-to-list 'emulation-mode-map-alists
+ (list (cons ',override-mode ,root-map)))
+ (,global-override-mode 1))
(if (or ',minor-modes ',major-modes)
;;bind keys in root-map
@@ -236,13 +267,13 @@ Declare a prefix command for MAP named COMMAND-NAME."
(evil-define-key state ,root-map (kbd key) ',prefix-cmd))))
;;bind in global maps
(dolist (key (list ,@keys))
- (if ,override-minor-modes
- (define-key ,root-map (kbd key) ',prefix-cmd)
- (global-set-key (kbd key) ',prefix-cmd)))
+ (when ,override-minor-modes
+ (define-key ,root-map (kbd key) ',prefix-cmd))
+ (global-set-key (kbd key) ',prefix-cmd))
(dolist (key (list ,@evil-keys))
(dolist (state ',evil-states)
- (when ,evil-use-local
- (push (list state (kbd key) ',prefix-cmd)
+ (when ,override-minor-modes
+ (push (list ',override-mode state (kbd key) ',prefix-cmd)
bind-map-evil-local-bindings))
(evil-global-set-key state (kbd key) ',prefix-cmd)))))))
(put 'bind-map 'lisp-indent-function 'defun)
@@ -292,10 +323,13 @@ concatenated with `bind-map-default-map-suffix'."
(put 'bind-map-for-minor-mode 'lisp-indent-function 'defun)
(defun bind-map-evil-local-mode-hook ()
+ ;; format is (OVERRIDE-MODE STATE KEY DEF)
(dolist (entry bind-map-evil-local-bindings)
- (let ((map (intern (format "evil-%s-state-local-map" (car entry)))))
- (when (and (boundp map) (keymapp (symbol-value map)))
- (define-key (symbol-value map) (cadr entry) (caddr entry))))))
+ (let ((map (intern (format "evil-%s-state-local-map" (nth 1 entry)))))
+ (when (and (nth 0 entry)
+ (boundp map)
+ (keymapp (symbol-value map)))
+ (define-key (symbol-value map) (nth 2 entry) (nth 3 entry))))))
(add-hook 'evil-local-mode-hook 'bind-map-evil-local-mode-hook)
;;;###autoload
- [nongnu] elpa/bind-map ebc4c9fb11 34/97: Remove bind-map-kbd hack, (continued)
- [nongnu] elpa/bind-map ebc4c9fb11 34/97: Remove bind-map-kbd hack, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map 8ec4516db2 48/97: Remove use of evil-define-key, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map c182707793 41/97: Remove unnecessary helper functions and reorg, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map b0b9e18947 66/97: Revert last commit, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map f51d4b0c0d 79/97: Add bind-map-for-modes-derived, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map 21b7ba7eca 30/97: Fix some docstrings, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map cc1db8958c 64/97: Version 0.1, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map 988f14eb77 65/97: Use evil-define-minor-mode-key for minor-mode keys, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map 292794739c 71/97: Fix incorrect check of override mode in local hook, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map b187069313 22/97: Add short versions for single major/minor mode, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map d45971cd40 46/97: Use minor mode for overriding behavior,
ELPA Syncer <=
- [nongnu] elpa/bind-map 8d6b489feb 50/97: Add some basic tests, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map 24d453a1e8 55/97: Call evil-normalize-maps for evil-keys, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map b47b98455f 87/97: Simplify macro exp. for bind-mapfor-mode-inherit, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map 078c522f6e 93/97: Fix Makefile, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map ffe5e63617 92/97: Version 1.1.0, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map 46438e30c8 02/97: README formatting, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map f835ed39fe 06/97: Minor changes, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map 8dea8e8f91 10/97: Grammatical fix in README, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map e5647f14cf 11/97: Clarify modes in README, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map c8fa049b70 13/97: Update Commentary section to match README, ELPA Syncer, 2022/01/20