use-package
use-package copied to clipboard
Allow multiple keymaps in :map argument
This PR augments bind-keys to support passing a list of keymaps as the :map argument.
When one wants to bind the same key/command pair in multiple keymaps, the current options have some drawbacks:
;; Option 1: Code duplication, problematic when duplicated keybindings are numerous
(use-package foopkg
:bind (:map bar-mode-map
("C-c x" . foocmd1)
("C-c y" . foocmd2)
:map baz-mode-map
("C-c x" . foocmd1)
("C-c y" . foocmd2)))
;; Option 2: Use a loop, sacrificing the convenience and readability of :bind
(use-package foopkg
:commands (foocmd1 foocmd2)
:init
(dolist (map (list bar-mode-map baz-mode-map))
(bind-keys :map map
("C-c x" . foocmd1)
("C-c y" . foocmd2))))
With the new way, it is possible to avoid duplication and still use :bind:
(use-package foopkg
:bind (:map (bar-mode-map baz-mode-map)
("C-c x" . foocmd1)
("C-c y" . foocmd2)))
Additionally this PR clarifies the documentation of bind-chords to reflect that this style is already available for that command.
Conflicts need resolving, please.
Hi @jwiegley, thanks. I've revised this and resolved the conflicts. I made one assumption that could use a second-guess, please see this comment. Other than that, it should be good to go. Cheers, Jacob. (cc: @Hugo-Heagren)
I was unable to update this PR directly, so I've opened another PR with the same changes @fishyfriend.