Skip to content

Commit

Permalink
Corfu: evil-repeat support
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronjensen committed Mar 23, 2024
1 parent 89aea40 commit 753aecc
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion modes/corfu/evil-collection-corfu.el
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,42 @@ This key theme variable may be refactored in the future so use with caution."
(kbd "C-u") 'corfu-scroll-down))

(advice-add 'corfu--setup :after (lambda (&rest _) (evil-normalize-keymaps)))
(advice-add 'corfu--teardown :after (lambda (&rest _) (evil-normalize-keymaps))))
(advice-add 'corfu--teardown :after (lambda (&rest _) (evil-normalize-keymaps)))

;; https://github.com/minad/corfu/pull/169
;; https://github.com/minad/corfu/pull/225
(defun evil-collection-corfu-unread-this-command-keys ()
(when (> (length (this-command-keys)) 0)
(setq unread-command-events (nconc
(listify-key-sequence (this-command-keys))
unread-command-events))
(clear-this-command-keys t)))

(cl-defmethod corfu--insert :around (status)
(if (or (eq this-command 'evil-collection-corfu-insert-exact)
(not (eq status 'exact)))
(cl-call-next-method)
(evil-collection-corfu-unread-this-command-keys)
(setq this-command 'evil-collection-corfu-insert-exact)))

(defun evil-collection-corfu-insert-exact ()
"Insert current candidate with the `exact' status.
Quit if no candidate is selected."
(interactive)
(if (>= corfu--index 0)
(corfu--insert 'exact)
(corfu-quit)))

(mapc #'evil-declare-ignore-repeat
'(corfu-next
corfu-previous
corfu-first
corfu-last))

(mapc #'evil-declare-change-repeat
'(corfu-insert
evil-collection-corfu-insert-exact
corfu-complete)))

(provide 'evil-collection-corfu)
;;; evil-collection-corfu.el ends here

0 comments on commit 753aecc

Please sign in to comment.