[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/bind-map f51d4b0c0d 79/97: Add bind-map-for-modes-derived
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/bind-map f51d4b0c0d 79/97: Add bind-map-for-modes-derived |
Date: |
Thu, 20 Jan 2022 07:59:26 -0500 (EST) |
branch: elpa/bind-map
commit f51d4b0c0db2c25bcef0de1533759fee356b52a0
Author: justbur <justin@burkett.cc>
Commit: justbur <justin@burkett.cc>
Add bind-map-for-modes-derived
See #4
---
bind-map.el | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 58 insertions(+), 4 deletions(-)
diff --git a/bind-map.el b/bind-map.el
index e624eaaca5..c6a4a330c6 100644
--- a/bind-map.el
+++ b/bind-map.el
@@ -125,6 +125,13 @@ be activated.")
(make-obsolete-variable 'bind-map-local-bindings
'bind-map-evil-local-bindings "2015-12-2")
+(defun bind-map-put-map-properties (map-sym &rest properties)
+ "Use put to add symbol properties to MAP-SYM."
+ (declare (indent 1))
+ (while properties
+ (put map-sym (pop properties)
+ (when properties (pop properties)))))
+
(defun bind-map-evil-local-mode-hook ()
"Called to activate local state maps in a buffer."
;; format is (OVERRIDE-MODE STATE KEY DEF)
@@ -273,10 +280,23 @@ mode maps. Set up by bind-map.el." map))
`((defvar ,map (make-sparse-keymap))
(unless (keymapp ,map)
(error "bind-map: %s is not a keymap" ',map))
- (defvar ,prefix-cmd nil)
- (setq ,prefix-cmd ,map)
- (setf (symbol-function ',prefix-cmd) ,map)
- (defvar ,root-map (make-sparse-keymap)))
+ (unless (and (boundp ',prefix-cmd)
+ (fboundp ',prefix-cmd))
+ (defvar ,prefix-cmd nil)
+ (setq ,prefix-cmd ,map)
+ (setf (symbol-function ',prefix-cmd) ,map))
+ (defvar ,root-map (make-sparse-keymap))
+ (bind-map-put-map-properties ',map
+ :root-map ',root-map
+ :active-var ',active-var
+ :prefix-cmd ',prefix-cmd
+ :override-minor-modes
',override-minor-modes
+ :override-mode-name ',override-mode
+ :keys ',keys
+ :evil-keys ',evil-keys
+ :evil-states ',evil-states
+ :minor-modes ',minor-modes
+ :major-modes ',major-modes))
(when minor-modes
`((dolist (mode ',minor-modes)
@@ -341,6 +361,40 @@ mode maps. Set up by bind-map.el." map))
(evil-normalize-keymaps)))))))))
(put 'bind-map 'lisp-indent-function 'defun)
+(defun bind-map--get-prop (keyword args parent-args)
+ (list keyword
+ (or (plist-get args keyword)
+ (plist-get parent-args keyword))))
+
+;;;###autoload
+(defmacro bind-map-for-modes-derived (map parent &rest args)
+ "Same as `bind-map' for MAP, except use some arguments from
+PARENT as defaults, which must be another map declared with
+`bind-map'. This is intended to be used with :major-modes
+or :minor-modes and will throw an error if not.
+
+The arguments that get recycled from PARENT (unless a new value
+is provided) are :override-minor-modes, :keys, :evil-keys,
+and :evil-states. All others must be declared explicitly."
+ (declare (indent defun))
+ (let* ((parent-args (symbol-plist parent))
+ (minor-modes (plist-get args :minor-modes))
+ (major-modes (plist-get args :major-modes)))
+ `(progn
+ (if (and (null ',minor-modes)
+ (null ',major-modes))
+ (user-error "bind-map-for-modes-derived called without \
+reference to :major-modes or :minor-modes")
+ (bind-map ,map
+ :prefix-cmd ,(plist-get args :prefix-cmd)
+ :override-mode-name ,(plist-get args :override-mode-name)
+ :minor-modes ,minor-modes
+ :major-modes ,major-modes
+ ,@(bind-map--get-prop :override-minor-modes args parent-args)
+ ,@(bind-map--get-prop :keys args parent-args)
+ ,@(bind-map--get-prop :evil-keys args parent-args)
+ ,@(bind-map--get-prop :evil-states args parent-args))))))
+
;;;###autoload
(defmacro bind-map-for-major-mode (major-mode-sym &rest args)
"Short version of `bind-map' if you want to bind a map for a
- [nongnu] elpa/bind-map b05ea98102 37/97: Add option to use local state maps, (continued)
- [nongnu] elpa/bind-map b05ea98102 37/97: Add option to use local state maps, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map 7d20946692 04/97: Add autoloads, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map 7de08fe592 43/97: Move a defvar and reword docstring, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map bb7a8b2258 59/97: Remove declare-function from previous commit, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map 6d05297e3c 20/97: Add another example and more detail to README, ELPA Syncer, 2022/01/20
- [nongnu] elpa/bind-map d47be94d23 63/97: Don't try to bind keys that are nil or "", ELPA Syncer, 2022/01/20
- [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 <=
- [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, 2022/01/20
- [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