Skip to content

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

Description

@yuki-tsubaki

Is this reasonable? Or is there some reason why this should not be done? The automatic parsing of key-strings like this seems to be the direction that the top user level binding commands are moving in Emacs (e.g. keymap-set).

Here is a prototype that I made (it could surely be improved and refined).

(defmacro evil-bind-key (state keymap key def &rest bindings)
"Like `evil-define-key' but automatically wraps KEY as (kbd KEY)."
`(evil-define-key ,state ,keymap (kbd ,key) ,def
    ,@(cl-loop for (k d) on bindings by #'cddr while def 
	collect `(kbd ,k)
	collect d)))

With this (nonsensical example), the following works.

(evil-bind-key 'normal emacs-lisp-mode
	       "M-." '+
	       "M-." '-)
;; Expands to
(evil-define-key 'normal emacs-lisp-mode
  (kbd "M-.") '+ (kbd "M-.") '-)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions