evil-collection icon indicating copy to clipboard operation
evil-collection copied to clipboard

Entering normal mode doesn't quit corfu popup

Open sudo-human opened this issue 3 years ago • 2 comments
trafficstars

I have the following corfu and evil-collection setup.

  :bind (:map corfu-map
         ("C-c" . corfu-quit))
  :custom
  (corfu-cycle t)                ;; Enable cycling for `corfu-next/previous'
  (corfu-auto t)                 ;; Enable auto completion
  (corfu-auto-delay 0)
  (corfu-auto-prefix 1)
  (tab-always-indent 'complete)
  
  :init
  (global-corfu-mode))

(use-package! evil-collection-corfu
  :when (featurep! :editor evil +everywhere)
  :defer t
  :init (setq evil-collection-corfu-key-themes '(default magic-return))
  :config
  (evil-collection-corfu-setup))

I read that evil-collection-corfu-setup will bind escape key to evil-collection-corfu-quit-and-escape function. But it seems that it is not working.

sudo-human avatar Sep 04 '22 08:09 sudo-human

Does eval (evil-collection-corfu-setup) help?

condy0919 avatar Sep 04 '22 10:09 condy0919

Does eval (evil-collection-corfu-setup) help?

Nope, I already tried this. All the other setup that's there in this function works except escape key.

sudo-human avatar Sep 05 '22 04:09 sudo-human

Do you have an emacs -Q? It works for meTM (though I'm not sure if it's anything specific to my setup.)

Feel free to re-open and sorry for the late replay.

jojojames avatar Mar 30 '23 00:03 jojojames

FWIW, I encountered the same issue and found that the reason was that I had set evil-disable-insert-state-bindings to t, to be able to use emacs bindings in insert mode. This seems to give ESC one job only, to return to normal state, which overrides the binding to corfu-quit. At least, that's my guess. Once I removed the evil-disable-insert-state-bindings setting (leaving it at the default nil), ESC does quit corfu.

fintelkai avatar Apr 06 '23 11:04 fintelkai

Someone found a solution for this and posted it on reddit:

(defvar my-override-keymap-alist '())
(add-to-ordered-list 'emulation-mode-map-alists 'my-override-keymap-alist 0)
(add-hook 'my-override-keymap-alist
          `(completion-in-region-mode . ,(define-keymap "<escape>" #'corfu-quit)))

I have used this now for several days and it does the trick, successfully combining evil-disable-insert-state-bindings and ESC doing corfu-quit.

This can be combined with evil-collection-corfu by replacing #'corfu-quit in the code with #'evil-collection-corfu-quit-and-escape.

fintelkai avatar Jun 23 '23 14:06 fintelkai

@fintelkai, thanks for posting this code. I am trying to get this to work, but cannot figure out what you mean by this:

I have used this now for several days and it does the trick, successfully combining evil-disable-insert-state-bindings and ESC doing corfu-quit.

This can be combined with evil-collection-corfu by replacing #'corfu-quit in the code with #'evil-collection-corfu-quit-and-escape.

Can you please the syntax you used to set this up?

atanasj avatar Jun 21 '24 02:06 atanasj

I have the following in my init.el after evil-collection and corfu have been loaded:

(evil-collection-corfu-setup)
(defvar my-override-keymap-alist '())
  (add-to-ordered-list 'emulation-mode-map-alists 'my-override-keymap-alist 0)
  (add-hook 'my-override-keymap-alist
            `(completion-in-region-mode . ,(define-keymap "<escape>" #'evil-collection-corfu-quit-and-escape)))

fintelkai avatar Jun 21 '24 10:06 fintelkai