Skip to content

Commit

Permalink
company-mode: Fix evil clobbering company-active-map
Browse files Browse the repository at this point in the history
fixes #664
  • Loading branch information
CeleritasCelery authored and jojojames committed Jan 28, 2023
1 parent 5016959 commit 8574309
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions modes/company/evil-collection-company.el
Original file line number Diff line number Diff line change
Expand Up @@ -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'."
Expand All @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 8574309

Please sign in to comment.