minad / cape

🦸cape.el - Completion At Point Extensions
GNU General Public License v3.0
573 stars 20 forks source link

cape-abbrev auto-completing without any text #85

Closed haji-ali closed 1 year ago

haji-ali commented 1 year ago

I noticed that cape-abbrev by default auto-completes even when there's no text that matches any of the abbrevations. In my case, (cape--abbrev-list) returns a single word ("word") and that word is inserted whenever I press TAB and no indentation is needed (or when I call cape-abbrev).

I would expect that the auto-completion should only activate if some text is inserted.

minad commented 1 year ago

This behavior seems expected to me.

-We could distinguish explicitly interactive invocation of cape-abbrev from invoking via completion-at-point-functions and only completely empty input in the explicit case. But I am not too fond of introducing such a distinction.

haji-ali commented 1 year ago

That's the issue then. I have corfu-auto-prefix (which is what I assume you mean) set to 3, but when I press TAB on an empty line I still get the auto-completion menu (or expansion in case of cape-abbrev).

BTW, I just tried calling cape-symbol using M-x on the latest versions of cape and corfu and noticed that the auto-complete menu shows up but pressing C-n and C-p doesn't cycle the candidates but moves the cursor and I cannot hide the menu until I call cape-symbol again. Do you see this on your end? If not, I will investigate the issue.

Strangely, if I call cape-symbol using a keyboard binding (C-c TAB s) it works as expected.

minad commented 1 year ago

Yes, it is expected that TAB opens the menu if completion at point is possible. Nothing wrong with that even with empty input.

The C-n and C-p movement seems like an issue of your config. Please test a minimal recipe with emacs -Q and let me know how it goes.

dwrz commented 5 months ago

I also ran into this and was surprised by the behavior.

Adding a few more abbrevs generated the pop-up, which I found less confusing.

https://github.com/minad/cape/assets/21134999/16869cff-7f9e-4891-8402-bc6a3737d3eb

minad commented 5 months ago

You can try the new setting:

(setq corfu-on-exact-match 'show)
minad commented 5 months ago

You can also check the behavior of default completion (with corfu-mode disabled). There you will see that if a Capf returns a single candidate, this candidate will be inserted when pressing TAB:

;; 1. Evaluate this code in *scratch*

(corfu-mode -1)

(setq-local completion-at-point-functions (list #'test-capf))

(defun test-capf ()
  (let ((bounds (or (bounds-of-thing-at-point 'word) (cons (point) (point)))))
    (list (car bounds) (cdr bounds) '("test"))))

;; 2. Press TAB, | is the cursor -> "test" will be inserted.
| <TAB>