-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
corfu-next deletes text lines when corfu-auto-prefix is 0 or when completion-at-point on a line with a single character #350
Comments
Hi! Can you please tell me how to reproduce this exactly? What keys do I have to press exactly step by step in the scratch buffer to trigger the problem? But anyway, a setting of |
Just pressing the down arrow. It also happens without autocomplete and pressing C-M-i on a line with a single char. (I edited the issue) |
I cannot reproduce the problem. Can you give me the exact buffer content, point position and key sequence needed to demonstrate the problem? Corfu should not delete any text - there is no code in Corfu which does this. Maybe you want |
With corfu-preview-current set to 'insert, there are lines deleted. When the next line is not empty, it deletes just one line, when there are empty lines after the completion, it deletes more. The lines are deleted when previewing and if the completion is canceled they come back. If the completion is confirmed, they stay deleted. Edit: I was mistaken, it does not fix it. Confirming the selection deletes lines. |
With
This deletes lines as described above. It seems to delete lines with some meaning... For example at the following code
when I press C-M-i at the '(' after the In the following where everything is on the same level of indentation it only deletes one line (the
|
It is not fixed by setting corfu-preview-current to nil, after all |
OK. I tested and the bug is with Emacs completion-at-point. Sorry to bother you. |
Oh wow, I can reproduce this now. It could be a bug in (package-initialize)
(global-corfu-mode)
(setq completion-styles '(emacs22))
( ;; <-- place the cursor directly after the ( and press M-TAB
;; comment
something The problem is that the completion bounds are somehow wrong, but only if the This must be quite an old bug. Congratulations for finding it. If you consider the problem serious enough, you may report it upstream. ;) |
Thanks :P I sent a bug report to bug-gnu-emacs@gnu.org. I included a link to this bug report for your observations. |
Thanks. Link to the bug: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=64903 |
elisp-completion-at-point calculates the completion region by running backward-sexp from (point) and storing that position as the beginning, then running forward-sexp from the beginning and storing that position as the end. elisp-completion-at-point does symbol completion, so the completion region should only cover a symbol. Therefore, elisp-completion-at-point checks whether the beginning of the completion region (the result from backward-sexp) is a quotation mark or open paren, which would indicate that the region covers a string or list, and returns nil in that case. If point is already at the start of a sexp (e.g. immediately after an open paren) then backward-sexp will not move point and the beginning of the completion region would (correctly) be the original point. forward-sexp, in this case, will move over the next sexp after point and include it in the completion region, even if it's a string or list. That has several bad effects: - An unrelated next sexp can be deleted by doing completion at the start of some earlier sexp (bug#64903, bug#68514) - The completion region can be very large, breaking some completion styles; if the next sexp is large enough, completion will fail with:: (invalid-regexp "Regular expression too big") - External completion packages can be broken by this, including corfu: minad/corfu#350 We fix this by mirroring the check on the character at start of the region. We now also check if the character at the end of the completion region is a quotation mark or close paren, and set the end of the region equal to the beginning in that case. This way, we avoid including a string or list in the completion region, but still allow completion to proceed. * lisp/progmodes/elisp-mode.el (elisp-completion-at-point): Avoid returning a completion region which includes a string or list. (bug#64903)
Using Debian 12 with the packaged Emacs 28.2 with GNOME
When corfu-auto is true, and corfu-auto-prefix is 0, pressing down-arrow/M-n/C-n (all bound only to corfu-next) during a completion, deletes some of the lines of text after the line being completed.
This does not happen when corfu-auto-prefix is 1.
Minimal init:
Edit:
It also happens when trying to compete (with C-M-i) a line that has only one character, not having corfu-auto enabled
Minimal init:
Same as above but without the ":custom [...]"
The text was updated successfully, but these errors were encountered: