company-mode: Fix evil clobbering company-active-map

fixes #664
This commit is contained in:
Troy Hinckley 2022-12-09 13:23:55 -07:00 committed by James
parent 5016959285
commit 8574309997
1 changed files with 17 additions and 0 deletions

View File

@ -33,6 +33,7 @@
(declare-function company-tng-mode "company-tng")
(declare-function company-grab-line "company")
(declare-function company-begin-backend "company")
(declare-function company-ensure-emulation-alist "company")
(defgroup evil-collection-company nil
"Evil bindings for `company-mode'."
@ -45,6 +46,13 @@
"The \='evil-company-extended' keybindings should be requested"
:type 'boolean)
(defcustom evil-collection-company-enable-keymap-protection t
"Prevent evil from breaking company completion keymap.
When non-nil, prevents evil from overriding `company-active-map'
after calling `company-doc-buffer'. If disabled, the completion
keymap will be in a broken state."
:type 'boolean)
(defvar company-active-map)
(defvar company-search-map)
@ -58,6 +66,12 @@
(memq evil-state evil-collection-company-supported-states))
(t t)))
(defun evil-collection-company-protect-keymap ()
"Prevent evil from overriding `company-mode' completion keymap."
(when (and evil-collection-company-enable-keymap-protection
(memq 'company-emulation-alist emulation-mode-map-alists))
(company-ensure-emulation-alist)))
;;;###autoload
(defun evil-collection-company-whole-lines (command &optional arg &rest _ignored)
"`company-mode' completion backend that completes whole-lines, akin to vim's
@ -112,6 +126,9 @@ C-x C-l."
(kbd "M-k") 'company-select-previous
(kbd "<escape>") 'company-search-abort)
;; https://github.com/emacs-evil/evil-collection/issues/664
(add-hook 'evil-local-mode-hook #'evil-collection-company-protect-keymap)
;; Make `company-mode' not show popup when not in supported state
(advice-add 'company-call-backend
:before-while 'evil-collection-company-supported-p))