Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close completion popup if text len is less than corfu-auto-prefix #455

Closed

Conversation

krydos
Copy link

@krydos krydos commented May 2, 2024

Currently the auto completion popup appears as soon as user enters corfu-auto-prefix number of characters but it never goes away even if user removes some characters. It may not sound like a problem but it freezes Emacs if there are too many options for completion.

For example (when corfu-auto-prefix == 3):

  • Enter (mes (I want to enter (message "...") but then I changed my mind and want to enter something else)
  • Completion popup appears
  • Delete s
  • Completion popup is still there even though the length of entered text is less than corfu-auto-prefix
  • Delete e
  • Completion popup is still there and (at least in my case) Emacs is getting frozen for a few seconds because there are too many options available for letter m to auto complete.

Expected behavior for me is to close the completion popup as soon as the number of entered characters are less than corfu-auto-prefix.

This issue is less prominent if you have a habit to useM-Backspace instead of Backspace-Many-Times as I used to do.
I suffer from this issue every day but I can't find anyone complaining about it which makes me think that I either missed a variable that actually fixes this issue or I maybe have too many completion sources which makes my Emacs slow...

In any case, let me know if you find this change valuable and let me know if I can improve anything code-wise.

Currently the auto completion popup appears as soon as user
enter corfu-auto-prefix number of characters but it never goes away
even if user removes some characters.

Depending on how many autocompletion sources configured it may freeze
Emacs especially at the moment when there is only one character left
for the autocompletion.
@minad
Copy link
Owner

minad commented May 2, 2024

Thanks for this proposal. It seems reasonable, but I am a little worried to change this behavior now. Also if you trigger manual completion, the popup won't go away again when deleting input. The popup must be dismissed explicitly with C-g or ESC.

In your comment there are a few red flags, regarding this feature request, which sound like a problematic configuration on your side:

...it freezes Emacs if there are too many options for completion...

...or I maybe have too many completion sources which makes my Emacs slow...

...I can't find anyone complaining about it...

Corfu should not freeze your Emacs. Corfu interrupts completion sources if they take too long and it is of course not recommended to use too many slow sources or sources creating tons of useless candidates. Can you please try to fix this, by reducing the amount of sources?

There are two other possibilities to resolve this:

  1. An alternative completion style which does not return candidates for short input. However this interferes with manual completion.
(defun short-all-completions (string table pred point)
  (and (length< string 4)
       (completion-emacs21-all-completions string table pred point)))

(defun short-try-completion (string table pred point)
  (and (length< string 4)
       (completion-emacs21-try-completion string table pred point)))

(add-to-list 'completion-styles-alist
             '(short
               short-try-completion
               short-all-completions
               "Basic completion with length limit for speed up."))
  1. Rebind DEL to another command which dismisses the popup for short input.

@krydos
Copy link
Author

krydos commented May 2, 2024

Thanks for such a quick reply @minad
I just went through my config and noticed that I have some cape-* functions added to completion-at-point-functions which may cause the slowness and apparently if no one else have this issue then it's not a package problem.

I can't also reproduce it with emacs -Q

I'll fix it on my end.

Thank you for suggestions on how to fix it!

@krydos krydos closed this May 2, 2024
@krydos krydos deleted the close-comp-popup-depending-on-autoprefix branch November 7, 2024 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants