clojure-emacs / cider

The Clojure Interactive Development Environment that Rocks for Emacs
https://cider.mx
GNU General Public License v3.0
3.54k stars 645 forks source link

Key bindings of company-mode don't work while evil-mode is enabled #2908

Closed CloseToZero closed 4 years ago

CloseToZero commented 4 years ago

Related issues: #2832, hlissner/doom-emacs#1335

Expected behavior

When company-mode completion is activated, the key bindings in company-active-map should take effect (or when searching through candidates, company-search-map should take effect).

Actual behavior

The key bindings of insert state (evil-mode) are used.

Steps to reproduce the problem

While evil-mode is enabled, trigger the company-mode completion inside cider-repl buffer, then try to press the keys defined inside the company-active-map, it will trigger the insert state key bindings of evil-mode.

Environment & Version information

CIDER version information

;; CIDER 1.0.0snapshot, nREPL 0.8.2
;; Clojure 1.10.1, Java 14.0.2

Lein/Boot version

Leiningen 2.9.4 on Java 14.0.2 OpenJDK 64-Bit Server VM

Emacs version

GNU Emacs 28.0.50

Operating system

Linux arch 5.7.12-arch1-1

More detail

Currently, every time function nrepl-bdecode executed, it will change the major-mode of " nrepl-decoding" buffer to fundamental-mode, which causes the key bindings of company-mode to be overridden. Remove the call to fundamental-mode inside nrepl-bdecode, the issue seems solved.

Reason

Every time company-mode completion is activated, it will call company-ensure-emulation-alist to ensure its company-emulation-alist is the first item of emulation-mode-map-alists, thus ensure its keymaps have higher priority (at least higher than evil-mode-map-alist, which contains the keymaps of evil-mode). This works most of the time.

The problem is whenever after-change-major-mode-hook executed, evil-mode will elevate the priority of its keymaps by putting the evil-mode-map-alist in the front of emulation-mode-map-alists. Since nrepl-bdecode change the major-mode of " nrepl-decoding" buffer to fundamental-mode while company-mode completion is activated, after-change-major-mode-hook executed, evil-mode elevate its keymaps, thus override the key bindings of company-mode.

Normally, during the time company-mode completion is activated, there won't have buffers change their major-mode, thus won't cause the above issue.

I don't know what's the appropriate way to handle this issue, maybe avoid change major-mode to fundamental-mode inside nrepl-bdecode?

" nrepl-decoding" buffer is created by get-buffer-create and the major mode for a newly created buffer is set to Fundamental mode. It's there any particular reason to call fundamental-mode manually inside nrepl-bdecode? (maybe some packages will change its major-mode?)

CloseToZero commented 4 years ago

I give a workaround in https://github.com/hlissner/doom-emacs/issues/1335#issuecomment-709691151.

jiacai2050 commented 3 years ago

Same issue here.

@bbatsov Do you think we should include this workaround in faq?