Use evil-with-delay

See 44add36e97
This commit is contained in:
condy 2023-08-28 23:29:53 +08:00 committed by Youmu
parent 1ad283f5b7
commit de0b62b604
1 changed files with 27 additions and 24 deletions

View File

@ -1,6 +1,6 @@
;;; evil-collection.el --- A set of keybindings for Evil mode -*- lexical-binding: t -*- ;;; evil-collection.el --- A set of keybindings for Evil mode -*- lexical-binding: t -*-
;; Copyright (C) 2017 James Nguyen ;; Copyright (C) 2017, 2023 James Nguyen
;; Author: James Nguyen <james@jojojames.com> ;; Author: James Nguyen <james@jojojames.com>
;; Pierre Neidhardt <mail@ambrevar.xyz> ;; Pierre Neidhardt <mail@ambrevar.xyz>
@ -437,10 +437,10 @@ functions added to this hook should include a \"&rest _rest\" for forward
compatibility.") compatibility.")
(defun evil-collection-define-operator-key (operator map-sym &rest bindings) (defun evil-collection-define-operator-key (operator map-sym &rest bindings)
"Defines a key on a specific operator e.g. yank or delete. "Define a key on a specific OPERATOR e.g. yank or delete.
This function is useful for adding specific binds to operator maps This function is useful for adding specific binds to operator maps
(e.g. `evil-yank' or `evil-delete') without erasing the original bind. \(e.g. `evil-yank' or `evil-delete') without erasing the original bind.
For example, say one wants to bind \"yf\" to something but also wants to keep For example, say one wants to bind \"yf\" to something but also wants to keep
\"yy\". \"yy\".
@ -449,7 +449,7 @@ This function takes care of checking the whitelist/blacklist against the full
binding. binding.
For example: For example:
(evil-collection-define-operator-key \='yank \(evil-collection-define-operator-key \='yank
\='pass-mode-map \"f\" \='pass-copy-field) \='pass-mode-map \"f\" \='pass-copy-field)
This will check \"yf\" against a user's white/blacklist and also record the This will check \"yf\" against a user's white/blacklist and also record the
@ -498,8 +498,8 @@ binding in `annalist' as so."
(defun evil-collection--filter-states (state) (defun evil-collection--filter-states (state)
"Return a list states after filtering STATE (a single symbol or list of symbols). "Return a list states after filtering STATE (a single symbol or list of symbols).
The return value adheres to `evil-collection-state-passlist' and The return value adheres to `evil-collection-state-passlist' and
`evil-collection-state-denylist'. When the STATE is `nil', which `evil-collection-state-denylist'. When the STATE is nil, which
means all states for `evil-define-key', return `nil'." means all states for `evil-define-key', return nil."
(let ((states (if (listp state) state (list state)))) (let ((states (if (listp state) state (list state))))
(seq-difference (seq-difference
(if evil-collection-state-passlist (if evil-collection-state-passlist
@ -707,16 +707,16 @@ invocation."
(dolist (mode-symbol modes) (dolist (mode-symbol modes)
(let ((keymap-symbol (intern (format "%S-map" mode-symbol)))) (let ((keymap-symbol (intern (format "%S-map" mode-symbol))))
(dolist (state states) (dolist (state states)
(evil-delay `(and (boundp ',keymap-symbol) (evil-with-delay `(and (boundp ',keymap-symbol)
(keymapp ,keymap-symbol)) (keymapp ,keymap-symbol))
`(evil-collection--translate-minor-mode-key `(after-load-functions
',state t
',mode-symbol nil
',translations (symbol-name
,destructive) (cl-gensym
'after-load-functions t nil (format "evil-collection-translate-key-in-%s" ,keymap-symbol))))
(symbol-name (cl-gensym (format "evil-collection-translate-key-in-%s" (evil-collection--translate-minor-mode-key state mode-symbol
keymap-symbol)))))))) translations destructive))))))
(defun evil-collection--translate-minor-mode-key (state (defun evil-collection--translate-minor-mode-key (state
mode-symbol mode-symbol
@ -812,13 +812,16 @@ invocation."
(setq states (list states))) (setq states (list states)))
(dolist (keymap-symbol keymaps) (dolist (keymap-symbol keymaps)
(dolist (state states) (dolist (state states)
(evil-delay `(and (boundp ',keymap-symbol) (evil-with-delay `(and (boundp ',keymap-symbol)
(keymapp ,keymap-symbol)) (keymapp ,keymap-symbol))
`(evil-collection--translate-key ',state ',keymap-symbol `(after-load-functions
',translations ,destructive) t
'after-load-functions t nil nil
(symbol-name (cl-gensym (format "evil-collection-translate-key-in-%s" (symbol-name
keymap-symbol))))))) (cl-gensym
(format "evil-collection-translate-key-in-%s" ,keymap-symbol))))
(evil-collection--translate-key state keymap-symbol
translations destructive)))))
;;;###autoload ;;;###autoload
(defmacro evil-collection-swap-key (states keymaps &rest args) (defmacro evil-collection-swap-key (states keymaps &rest args)
@ -839,7 +842,7 @@ should consist of key swaps (e.g. \"a\" \"b\" is equivalent to \"a\" \"b\" \"b\"
"Wrapper around `evil-collection-translate-minor-mode-key' for swapping keys. "Wrapper around `evil-collection-translate-minor-mode-key' for swapping keys.
STATES, MODES, and ARGS are passed to STATES, MODES, and ARGS are passed to
`evil-collection-translate-minor-mode-key'. ARGS should consist of key swaps `evil-collection-translate-minor-mode-key'. ARGS should consist of key swaps
(e.g. \"a\" \"b\" is equivalent to \"a\" \"b\" \"b\" \"a\" \(e.g. \"a\" \"b\" is equivalent to \"a\" \"b\" \"b\" \"a\"
with `evil-collection-translate-minor-mode-key') and optionally keyword with `evil-collection-translate-minor-mode-key') and optionally keyword
arguments for `evil-collection-translate-minor-mode-key'." arguments for `evil-collection-translate-minor-mode-key'."
(declare (indent defun)) (declare (indent defun))