I use use-package
to manage installed packages and bind-key
to assign actions to custom keys that I like.
I override most of the default Emacs keybinding (e.g. C-n becomes M-k, C-p becomes M-i), but I'm OK with other modes overriding my keybinding scheme. Sometimes, I want my keybinding persist, however. I want M-k mean something else, than in default Gnus or Helm.
However they all conflict with each other on Emacs startup, because I can't add a binding to a keymap, if it doesn't exist (because use-package
sometimes defers loading of a package). E.g., the following commands throw errors (e.g. (void-variable helm-map)
), because Helm and Gnus aren't yet fully loaded.
(bind-key "M-Y" 'helm-end-of-buffer helm-map)
(bind-key "M-k" 'helm-next-line helm-find-files-map)
(bind-key "M-s" 'other-window gnus-summary-mode-map)
I have all my use-package
invocations in one file and bind-key
for custom keybindings in another file. I don't want to put bindings into use-package
calls, because maybe I want to publish my custom keybinding scheme as a standalone package. What if I want someone installing my scheme had Helm and Gnus local keybindings overriden too?
How do I manage mode-local keybindings using bind-key
, so that all keys are set even if packages are loaded lately, and all key settings are inside one file?