From 85743099972bfcc4d7788db70dfe33e864eba090 Mon Sep 17 00:00:00 2001 From: Troy Hinckley Date: Fri, 9 Dec 2022 13:23:55 -0700 Subject: [PATCH] company-mode: Fix evil clobbering company-active-map fixes #664 --- modes/company/evil-collection-company.el | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/modes/company/evil-collection-company.el b/modes/company/evil-collection-company.el index 08dc7be..7042221 100644 --- a/modes/company/evil-collection-company.el +++ b/modes/company/evil-collection-company.el @@ -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 "") '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))