minad / corfu

:desert_island: corfu.el - COmpletion in Region FUnction
GNU General Public License v3.0
1.15k stars 43 forks source link

corfu-next deletes text lines when corfu-auto-prefix is 0 or when completion-at-point on a line with a single character #350

Closed t-c-acc closed 1 year ago

t-c-acc commented 1 year ago

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:

(require 'package)
(setq package-archives '(("GNU ELPA" . "https://elpa.gnu.org/packages/")
                         ("NonGNU ELPA" . "https://elpa.nongnu.org/nongnu/")
                         ("MELPA Stable" . "https://stable.melpa.org/packages/")
                         ("MELPA" . "https://melpa.org/packages/"))
        package-archive-priorities '(("GNU ELPA" . 10)
                                     ("NonGNU ELPA" . 9)
                                     ("MELPA Stable" . 5)
                                     ("MELPA" . 1)))
(package-initialize)
(unless package-archive-contents (package-refresh-contents))
(unless (package-installed-p 'use-package) (package-install 'use-package))
(require 'use-package)
(require 'use-package-ensure)
(setq use-package-always-ensure t)

(use-package corfu
    :init (global-corfu-mode)
    :custom
    (corfu-auto t)
    (corfu-auto-prefix 1))

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 [...]"

minad commented 1 year ago

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 corfu-auto-prefix=0 is invalid. The smallest reasonable value is 1.

t-c-acc commented 1 year ago

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)

minad commented 1 year ago

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 corfu-preview-current=nil to disable the preview overlay?

t-c-acc commented 1 year ago

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.

t-c-acc commented 1 year ago

With emacs -q --load ~/testinit.el, testinit.el being what I posted above, without corfu-auto.

This deletes lines as described above.

It seems to delete lines with some meaning...

For example at the following code

(use-package modus-themes
   :config
   (
   ;; Add all your customizations prior to loading the themes
   (setq modus-themes-italic-constructs t
         modus-themes-bold-constructs t
         modus-themes-mixed-fonts t)

   ;; Maybe define some palette overrides, such as by using our presets
   (setq modus-themes-common-palette-overrides
         nil)
[...]

when I press C-M-i at the '(' after the :config it deletes up to the line before ;; Maybe [...]

In the following where everything is on the same level of indentation it only deletes one line (the (setq-default cursor-type '(bar . 2))):

(setq-default visible-bell t)
(
(setq-default cursor-type '(bar . 2))
(set-fringe-mode 4)
(scroll-bar-mode -1)
t-c-acc commented 1 year ago

It is not fixed by setting corfu-preview-current to nil, after all

t-c-acc commented 1 year ago

OK. I tested and the bug is with Emacs completion-at-point. Sorry to bother you.

minad commented 1 year ago

Oh wow, I can reproduce this now. It could be a bug in elisp-completion-at-point or the emacs22 completion style. I tried the following snippet in emacs -Q:

(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 emacs22 completion style is used. The completion bounds cross the newlines over the ;; comment. It also happens with default completion-at-point without Corfu, such that multiple lines are deleted. It does not happen with the basic, emacs21 or substring completion styles.

This must be quite an old bug. Congratulations for finding it. If you consider the problem serious enough, you may report it upstream. ;)

t-c-acc commented 1 year ago

Thanks :P

I sent a bug report to bug-gnu-emacs@gnu.org. I included a link to this bug report for your observations.

minad commented 1 year ago

Thanks. Link to the bug: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=64903