spacemacs icon indicating copy to clipboard operation
spacemacs copied to clipboard

Escape does not close autocomplete window.

Open jordwalke opened this issue 9 years ago • 22 comments

Hi, I'm brand new to Emacs so thank you for your patience. I'm only even trying Emacs thanks to Spacemacs. The issue I'm seeing is that when hitting escape, Evil goes into normal mode as expected, but any autocomplete window that is open does not close.

This is my entire config:

  (load-theme 'spacemacs-light t)
  (set-face-attribute 'mode-line nil :box nil)
  (set-face-attribute 'mode-line-inactive nil :box nil)
  ;; Don't highlight line
  (global-hl-line-mode -1) ; Disable current line highlight
  (setq evil-want-fine-undo nil)
  (setq evil-move-cursor-back nil)
  (global-set-key (kbd "s-p") 'helm-M-x)
  ; (setq powerline-default-separator 'utf-8)
  (setq powerline-default-separator nil)
  (global-vi-tilde-fringe-mode -1)

These are my enabled layers:

     company
     ;; To toggle autocompletion on:
     ;; space t a 
     auto-completion
     ;; better-defaults
     emacs-lisp
     themes-megapack
     ;; Basic mac keybindings. (Cmd is super, alt is meta)
     osx

I'm on Mac OS Yosemite.

jordwalke avatar Dec 20 '15 08:12 jordwalke

Old bug, no activity. I just tried reproducing this on develop but I can't. Is this still a problem?

TheBB avatar Jun 14 '16 06:06 TheBB

I'm seeing the same thing, but only with some company backends (??). Worse, it doesn't really appear to fully exit insert mode (keys still get inserted until the popup closes).

Specifically, I can reproduce this with company-emoji and notmuch-company.

Stebalien avatar Aug 21 '16 01:08 Stebalien

@Stebalien Can you still reproduce this? I'm unable to reproduce the issue using company-emoji.

System Info :computer:

  • OS: windows-nt
  • Emacs: 24.5.1
  • Spacemacs: 0.200.3
  • Spacemacs branch: develop (rev. b550945)
  • Graphic display: t
  • Distribution: spacemacs
  • Editing style: vim
  • Completion: helm
  • Layers:
(auto-completion better-defaults bibtex c-c++ dash emacs-lisp git github gtags html java javascript latex markdown ocaml org python racket ranger rust shell shell-scripts helm syntax-checking emoji)

NJBS avatar Oct 19 '16 15:10 NJBS

Yes, I still can.

  1. Open a scratch buffer.
  2. Set the company-backends to company-emoji: (setq company-backends '(company-emoji))
  3. Enable company: (company-mode)
  4. Enter insert mode, type :ta in the buffer, and wait for auto-complete.
  5. Hit escape.

Stebalien avatar Oct 19 '16 16:10 Stebalien

Ah, indeed I can now reproduce this.

Strange 😕

NJBS avatar Oct 19 '16 19:10 NJBS

I also have this problem, using auto-completion with hardly any customization on the develop branch of spacemacs.

Full .spacemacs (permalink)

https://github.com/cjolowicz/dotfiles/blob/d6b82bf3e28e9cdcc4b4fbb37474a491b2e53b56/spacemacs/.spacemacs#L12-L13

System Info :computer:

  • OS: darwin
  • Emacs: 26.2
  • Spacemacs: 0.300.0
  • Spacemacs branch: develop (rev. 5df46b200)
  • Graphic display: t
  • Distribution: spacemacs
  • Editing style: vim
  • Completion: helm
  • Layers:
((auto-completion :variables auto-completion-complete-with-key-sequence "jk")
 better-defaults
 (c-c++ :variables c-c++-default-mode-for-headers 'c++-mode c-c++-enable-clang-support t c-c++-backend 'rtags)
 chrome cmake docker emacs-lisp graphviz git helm html
 (javascript :variables javascript-fmt-tool 'prettier javascript-import-tool 'import-js js2-basic-offset 2 js-indent-level 2 js-switch-indent-offset 2 node-add-modules-path t)
 (json :variables json-fmt-tool 'prettier)
 (markdown :variables markdown-command "pandoc")
 multiple-cursors nginx
 (org :variables org-enable-github-support t org-enable-bootstrap-support t org-enable-org-journal-support t org-enable-hugo-support t org-enable-trello-support t org-enable-jira-support t)
 osx pandoc prettier
 (python :variables python-test-runner 'pytest python-formatter 'black python-fill-column 99)
 react rust
 (shell :variables shell-default-height 30 shell-default-position 'bottom)
 shell-scripts spell-checking sql syntax-checking themes-megapack theming treemacs version-control xclipboard yaml)
  • System configuration features: JPEG RSVG IMAGEMAGICK GLIB NOTIFY ACL GNUTLS LIBXML2 ZLIB TOOLKIT_SCROLL_BARS NS MODULES THREADS LCMS2

cjolowicz avatar Jul 12 '19 09:07 cjolowicz

It's working for me. The auto completion window appears after typing dot in .spacemacs. And pressing Esc closes it.

System Info :computer:

  • OS: windows-nt
  • Emacs: 26.2
  • Spacemacs: 0.300.0
  • Spacemacs branch: develop (rev. cd24a7342)
  • Graphic display: t
  • Distribution: spacemacs
  • Editing style: vim
  • Completion: helm
  • Layers:
(autohotkey auto-completion emacs-lisp git helm markdown multiple-cursors org python syntax-checking treemacs version-control)
  • System configuration features: XPM JPEG TIFF GIF PNG RSVG SOUND NOTIFY ACL GNUTLS LIBXML2 ZLIB TOOLKIT_SCROLL_BARS THREADS LCMS2

duianto avatar Jul 12 '19 22:07 duianto

Strange, I can't reproduce it either now. Will report back if it reoccurs.

cjolowicz avatar Jul 13 '19 15:07 cjolowicz

Ok, reproduced it now:

image

Keystrokes: c w ArtistDialog ESC j b w ArtistDialog ESC l l

Watch the indicator in the modeline change from green to yellow to see when ESC is pressed. The autocomplete window does not close. What's more, the j should move down a line in normal mode, but it is inserted as if still in insert mode.

The b then correctly moves back a word. We repeat the same sequence up to ESC. Again, the autocomplete window does not close. However, now the l correctly moves to the right, even though it happens under the same circumstances as the j earlier. The second l causes the autocomplete window to close.

cjolowicz avatar Jul 15 '19 12:07 cjolowicz

I'm also able to reproduce it now, it seems to only occur when the completion popup shows file/dir paths.

At first I thought that it was because the cursor moves backwards by default and the popup might be trying to check for new candidates at the cursors new position. But when I set the variable move back variable to nil (default is t):

(setq evil-move-cursor-back nil)

Then the same issue occurs. The popup remains/reopens.

Reproduction steps:

This can be seen in .spacemacs if I type:

  • "~/.e The popup shows candidates for files/dirs starting with .e, if you don't have any then try another letter, or just type . (period), or if you don't have any . files, try another letter.
  • While still in insert state, move backwards C-b and forwards C-f, the completion popup tries to match the path from the cursors position. "~/.| (cursor marked as the vertical bar | , positioned after the period) shows files starting with a period. "~/| (cursor after the slash) shows all files/directories in the home dir.
  • Move the cursor after the e in the string "~/.e".
  • Press Esc The completion popup blinks (it probably closes and reopens quickly) now showing matches for files starting with a period.

In this state with the completion popup open and the cursor in normal state, I'm able to move left h and right l (lower case L) to match on either ~/. or on ~/.e. Moving to the left of the slash closes the popup.

You said that j inserts the character for you. But for me the cursor moves down and the completion popup closes, the equivalent happens with k.

duianto avatar Jul 15 '19 20:07 duianto

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

github-actions[bot] avatar Jul 14 '20 20:07 github-actions[bot]

I am experiencing this issue using the default auto-completion layer with no additional changes.

emesterhazy avatar Aug 15 '20 18:08 emesterhazy

Me too.

xged avatar Feb 11 '21 13:02 xged

A (potentially very naive) quickfix for evil users could look roughly like

(defun my-escape-from-company ()
  (interactive)
  (company-abort)
  (evil-escape))

(with-eval-after-load 'company
  (key-chord-define company-active-map "jf" 'my-escape-from-company))

where you would need to replace "jf" with your escape sequence (e.g. "fd").

For me this currently works but this seems to be a somewhat elusive issue which may depend on the individual setup...

stephenkraemer avatar May 19 '21 09:05 stephenkraemer

The issue is still present.

A (potentially very naive) quickfix for evil users could look roughly like

That makes my autocompletion not show up at all. :/

upbqdn avatar May 15 '22 16:05 upbqdn

C-g should close auto-completion menu.

lebensterben avatar May 16 '22 01:05 lebensterben

That's what I do, but then I'm doing <escape> <C-g> or <C-g> <escape>, which is not ergonomic. I never need access to autocompletion after I press <escape>. It would be great to fix this, but I haven't found a way unfortunately.

I wonder how others deal with this. Do you also use <C-g> + <escape>?

upbqdn avatar May 16 '22 20:05 upbqdn

I only need to use C-g.

lebensterben avatar May 17 '22 00:05 lebensterben

I assume you use hybrid or vim mode as well. So you treat the closing of the autocompletion and the transition to normal mode as separate operations I guess. However, here you can see that the transition to normal mode doesn't work if you don't close the autocompletion first https://github.com/syl20bnr/spacemacs/issues/4242#issuecomment-511379029. The same thing happens to me.

upbqdn avatar May 18 '22 14:05 upbqdn

+1, this sometimes happens to me too on the most recent develop (4688cd7d). When I hit escape the popup sometimes closes correctly, and sometimes flickers and then reappears and stays on the screen in normal mode.

e-matteson avatar Sep 29 '22 14:09 e-matteson

This workaround has been working for me, and I haven't noticed any unintended side effects:

  (add-hook 'company-mode-hook
   (lambda ()
     (add-hook 'evil-normal-state-entry-hook
               (lambda ()
                 (company-abort)))))

e-matteson avatar Oct 11 '22 17:10 e-matteson

Unfortunately @e-matteson's workaround isn't working for me, because it seems to call company-abort after every key stroke. So it closes the candidate list again and again. I think the problem lies in that evil-escape does not have an evil-escape--escape-insert-state function that would call company-abort like something that is done in evil-escape--escape-emacs-state for example. See https://github.com/syl20bnr/evil-escape/blob/f4e9116bfbaac8c9d210c17ad488e0982291245f/evil-escape.el#L166 and https://github.com/syl20bnr/evil-escape/blob/f4e9116bfbaac8c9d210c17ad488e0982291245f/evil-escape.el#L260 The problem also seems especially prevalent when using lsp-mode and it's preventing me from using just "fd" to get back to normal mode.

As a workaround I came up with the following solution:

(with-eval-after-load 'evil-escape
  (defun company-abort-on-evil-escape ()
    (require 'company)
    (company-abort))
  (advice-add 'evil-escape-func :after #'company-abort-on-evil-escape))

niontrix avatar May 24 '23 08:05 niontrix