feat: add evil-bind-keys for shorthand binding
#2003
+254
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 packagebind-keys. The entry-points are the two macrosevil-bind-keysandevil-bind-keys*, which expand as drop-in replacements for the native macrosbind-keysandbind-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 ininit.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-keysfor all of my config (throughuse-package's:bind), but kept running into issues where Evil bindings like above withbind-keywouldn'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. Usingevil-define-keyinstead 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.