use-package icon indicating copy to clipboard operation
use-package copied to clipboard

Allow multiple keymaps in :map argument

Open fishyfriend opened this issue 5 years ago • 1 comments

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.

fishyfriend avatar Apr 15 '20 10:04 fishyfriend

Conflicts need resolving, please.

jwiegley avatar Sep 13 '22 15:09 jwiegley

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)

fishyfriend avatar Sep 29 '22 10:09 fishyfriend

I was unable to update this PR directly, so I've opened another PR with the same changes @fishyfriend.

jwiegley avatar Nov 15 '22 17:11 jwiegley