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,32 +352,38 @@ 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)))
((and (boundp map-sym) (keymapp (symbol-value map-sym)))
(condition-case-unless-debug err (defun evil-collection--define-key (state map-sym bindings)
(apply #'evil-define-key* "Workhorse function for `evil-collection-define-key'.
state (symbol-value map-sym) filtered-bindings)
(error See `evil-collection-define-key' docstring for more details."
(message "evil-collection: error setting key in %s %S" (cond ((null bindings))
map-sym err)))) ((and (boundp map-sym) (keymapp (symbol-value map-sym)))
((boundp map-sym) (condition-case-unless-debug err
(user-error "evil-collection: %s is not a keymap" map-sym)) (apply #'evil-define-key*
(t state (symbol-value map-sym) bindings)
(let* ((fname (format "evil-collection-define-key-in-%s" map-sym)) (error
(fun (make-symbol fname))) (message "evil-collection: error setting key in %s %S"
(fset fun `(lambda (&rest args) map-sym err))))
(when (and (boundp ',map-sym) (keymapp ,map-sym)) ((boundp map-sym)
(remove-hook 'after-load-functions #',fun) (user-error "evil-collection: %s is not a keymap" map-sym))
(condition-case-unless-debug err (t
(apply #'evil-define-key* (let* ((fname (format "evil-collection-define-key-in-%s" map-sym))
',state ,map-sym ',filtered-bindings) (fun (make-symbol fname)))
(error (fset fun `(lambda (&rest args)
(message (when (and (boundp ',map-sym) (keymapp ,map-sym))
,(format (remove-hook 'after-load-functions #',fun)
"evil-collection: error setting key in %s %%S" (condition-case-unless-debug err
map-sym) (apply #'evil-define-key*
err)))))) ',state ,map-sym ',bindings)
(add-hook 'after-load-functions fun t)))))) (error
(message
,(format
"evil-collection: error setting key in %s %%S"
map-sym)
err))))))
(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.