Skip to content

Conversation

@LuigiPiucco
Copy link

@LuigiPiucco LuigiPiucco commented Feb 2, 2026

First, I opened this as a pull request because I already had a working implementation, but it really is a feature request as well, which may be deemed undesired later. If these changes are considered out-of-scope, I'll publish a package with the functionality later, but I think the best place to put it would be within Evil itself. About what is implemented:

Introduces a new file, evil-bind-keys, which implements an equivalent of the new Emacs built-in package bind-keys. The entry-points are the two macros evil-bind-keys and evil-bind-keys*, which expand as drop-in replacements for the native macros bind-keys and bind-keys*, but with special handling when Evil states are specified. For a key sequence like "<normal-state> C-RET", instead of generating (bind-key "<normal-state> C-RET" DEF MAP), it generates (evil-define-key 'normal MAP (kbd "C-RET") DEF). The latter causes the binding to be properly defined and work more deterministically, whereas using the former may have subtle issues with load order of other packages that define the MAP, and fail to work if used in init.el.

This closes #1999, as that request is satisfied by the macros, though they can solve other issues as well. Specifically, I developed this because I wanted to use bind-keys for all of my config (through use-package's :bind), but kept running into issues where Evil bindings like above with bind-key wouldn't work if they were bound inside a keymap created by a remote package. It seemed like they would get overwritten in-between loading my config and using the bindings interactively, causing the keymap to forget Evil auxiliary maps. Using evil-define-key instead fixed all such issues.

This PR lacks documentation and tests for now, because I'd first like to get an approval that this can be included in the project. I'm also open to any suggestions/requests the maintainers may have.

Introduces a new file, `evil-bind-keys`, which implements an
equivalent of the new Emacs built-in feature `bind-keys`. The
entry-points are the two macros `evil-bind-keys` and
`evil-bind-keys*`, which expand as drop-in replacements for the native
macros `bind-keys` and `bind-keys*`, but with special handling when
evil states are specified. For a key sequence like "<normal-state>
C-RET", instead of generating `(bind-key "<normal-state> C-RET" DEF
MAP)`, it generates `(evil-define-key 'normal MAP (kbd "C-RET")
DEF)`. The latter causes the binding to be properly defined and work
more deterministically, whereas using the former may have subtle
issues with load order of other packages that define the MAP, and fail
to work if used in `init.el`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Variant of evil-bind-key that automatically wraps KEY as (kbd KEY) like keymap-set

1 participant