Factor out binding implementation from evil-collection-define-key

This commit is contained in:
James Nguyen 2021-01-31 20:18:13 -08:00 committed by James N
parent 61e5a5ba33
commit c02184f2fc
1 changed files with 32 additions and 26 deletions

View File

@ -352,11 +352,17 @@ to filter keys on the basis of `evil-collection-key-whitelist' and
(push key filtered-bindings) (push key filtered-bindings)
(push def filtered-bindings)))) (push def filtered-bindings))))
(setq filtered-bindings (nreverse filtered-bindings)) (setq filtered-bindings (nreverse filtered-bindings))
(cond ((null filtered-bindings)) (evil-collection--define-key state map-sym filtered-bindings)))
(defun evil-collection--define-key (state map-sym bindings)
"Workhorse function for `evil-collection-define-key'.
See `evil-collection-define-key' docstring for more details."
(cond ((null bindings))
((and (boundp map-sym) (keymapp (symbol-value map-sym))) ((and (boundp map-sym) (keymapp (symbol-value map-sym)))
(condition-case-unless-debug err (condition-case-unless-debug err
(apply #'evil-define-key* (apply #'evil-define-key*
state (symbol-value map-sym) filtered-bindings) state (symbol-value map-sym) bindings)
(error (error
(message "evil-collection: error setting key in %s %S" (message "evil-collection: error setting key in %s %S"
map-sym err)))) map-sym err))))
@ -370,14 +376,14 @@ to filter keys on the basis of `evil-collection-key-whitelist' and
(remove-hook 'after-load-functions #',fun) (remove-hook 'after-load-functions #',fun)
(condition-case-unless-debug err (condition-case-unless-debug err
(apply #'evil-define-key* (apply #'evil-define-key*
',state ,map-sym ',filtered-bindings) ',state ,map-sym ',bindings)
(error (error
(message (message
,(format ,(format
"evil-collection: error setting key in %s %%S" "evil-collection: error setting key in %s %%S"
map-sym) map-sym)
err)))))) err))))))
(add-hook 'after-load-functions fun t)))))) (add-hook 'after-load-functions fun t)))))
(defun evil-collection-inhibit-insert-state (map-sym) (defun evil-collection-inhibit-insert-state (map-sym)
"Unmap insertion keys from normal state. "Unmap insertion keys from normal state.