]> git.eshelyaron.com Git - emacs.git/commitdiff
bind-keys-form: new keyword :repeat-map, for defining repeat maps
authorHugo Heagren <hugo@heagren.com>
Sun, 16 Jan 2022 00:21:36 +0000 (00:21 +0000)
committerHugo Heagren <hugo@heagren.com>
Fri, 28 Jan 2022 22:37:06 +0000 (22:37 +0000)
use-package-normalize/:bind: allow keyword :repeat-map.

bind-keys-form: Add keyword :repeat-map. Specifying a symbol as the
repeat-map defines a keymap with that name (and with the docstring
`repeat-doc', if specified). Symbols for functions bound to keys under
the scope of :repeat-map have their 'repeat-map property set to this
map. Update docstring (and that of `bind-keys') to reflect changes.

Rename `doc' to `prefix-doc' for clarity and consistency with
'repeat-doc'.

lisp/use-package/bind-key.el
lisp/use-package/use-package-bind-key.el

index 1d611c2933cb55589e69c8b00ddee2da37771c79..bb09a6935a82b9a385fbd16b2e32d9c7906e6d8e 100644 (file)
@@ -257,14 +257,22 @@ Accepts keyword arguments:
                          for these bindings
 :prefix-docstring STR  - docstring for the prefix-map variable
 :menu-name NAME        - optional menu string for prefix map
+:repeat-docstring STR  - docstring for the repeat-map variable
+:repeat-map MAP        - name of the repeat map that should be created
+                         for these bindings. If specified, the
+                         'repeat-map property of each command bound
+                         (within the scope of the :repeat-map keyword)
+                         is set to this map.
 :filter FORM           - optional form to determine when bindings apply
 
 The rest of the arguments are conses of keybinding string and a
 function symbol (unquoted)."
   (let (map
-        doc
+        prefix-doc
         prefix-map
         prefix
+        repeat-map
+        repeat-doc
         filter
         menu-name
         pkg)
@@ -276,11 +284,18 @@ function symbol (unquoted)."
                         (not prefix-map))
                    (setq map (cadr args)))
                   ((eq :prefix-docstring (car args))
-                   (setq doc (cadr args)))
+                   (setq prefix-doc (cadr args)))
                   ((and (eq :prefix-map (car args))
                         (not (memq map '(global-map
                                          override-global-map))))
                    (setq prefix-map (cadr args)))
+                  ((eq :repeat-docstring (car args))
+                   (setq repeat-doc (cadr args)))
+                  ((and (eq :repeat-map (car args))
+                        (not (memq map '(global-map
+                                         override-global-map))))
+                   (setq repeat-map (cadr args))
+                   (setq map repeat-map))
                   ((eq :prefix (car args))
                    (setq prefix (cadr args)))
                   ((eq :filter (car args))
@@ -327,13 +342,16 @@ function symbol (unquoted)."
         (append
          (when prefix-map
            `((defvar ,prefix-map)
-             ,@(when doc `((put ',prefix-map 'variable-documentation ,doc)))
+             ,@(when prefix-doc `((put ',prefix-map 'variable-documentation ,prefix-doc)))
              ,@(if menu-name
                    `((define-prefix-command ',prefix-map nil ,menu-name))
                  `((define-prefix-command ',prefix-map)))
              ,@(if (and map (not (eq map 'global-map)))
                    (wrap map `((bind-key ,prefix ',prefix-map ,map ,filter)))
                  `((bind-key ,prefix ',prefix-map nil ,filter)))))
+         (when repeat-map
+           `((defvar ,repeat-map (make-sparse-keymap)
+               ,@(when repeat-doc `(,repeat-doc)))))
          (wrap map
                (cl-mapcan
                 (lambda (form)
@@ -341,7 +359,11 @@ function symbol (unquoted)."
                     (if prefix-map
                         `((bind-key ,(car form) ,fun ,prefix-map ,filter))
                       (if (and map (not (eq map 'global-map)))
-                          `((bind-key ,(car form) ,fun ,map ,filter))
+                          ;; Only needed in this branch, since when
+                          ;; repeat-map is non-nil, map is always
+                          ;; non-nil
+                          `(,@(when repeat-map `((put ,fun 'repeat-map ',repeat-map)))
+                            (bind-key ,(car form) ,fun ,map ,filter))
                         `((bind-key ,(car form) ,fun nil ,filter))))))
                 first))
          (when next
@@ -361,6 +383,12 @@ Accepts keyword arguments:
                          for these bindings
 :prefix-docstring STR  - docstring for the prefix-map variable
 :menu-name NAME        - optional menu string for prefix map
+:repeat-docstring STR  - docstring for the repeat-map variable
+:repeat-map MAP        - name of the repeat map that should be created
+                         for these bindings. If specified, the
+                         'repeat-map property of each command bound
+                         (within the scope of the :repeat-map keyword)
+                         is set to this map.
 :filter FORM           - optional form to determine when bindings apply
 
 The rest of the arguments are conses of keybinding string and a
index e476b060ad6c712694670d45fb05200c8203ac95..d056d4266cc1661fe95e879473bf3d63d6a6fff8 100644 (file)
@@ -86,6 +86,8 @@ deferred until the prefix key sequence is pressed."
          ;;   :prefix-docstring STRING
          ;;   :prefix-map SYMBOL
          ;;   :prefix STRING
+        ;;   :repeat-docstring STRING
+         ;;   :repeat-map SYMBOL
          ;;   :filter SEXP
          ;;   :menu-name STRING
          ;;   :package SYMBOL
@@ -93,6 +95,8 @@ deferred until the prefix key sequence is pressed."
               (and (eq x :prefix) (stringp (cadr arg)))
               (and (eq x :prefix-map) (symbolp (cadr arg)))
               (and (eq x :prefix-docstring) (stringp (cadr arg)))
+             (and (eq x :repeat-map) (symbolp (cadr arg)))
+              (and (eq x :repeat-docstring) (stringp (cadr arg)))
               (eq x :filter)
               (and (eq x :menu-name) (stringp (cadr arg)))
               (and (eq x :package) (symbolp (cadr arg))))