minad / cape

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

Allow setting minimum prefix length for cape-dabbrev #33

Closed accelbread closed 2 years ago

accelbread commented 2 years ago

Hi, I'm having an issue where cape-dabbrev is overriding a prior capf.

I'm using corfu with corfu-auto. In a buffer where cape-dabbrev is after another capf, and the first capf only completes after 2 characters, the first capf does not show. After the first character, I get completions from cape-dabbrev, and additional characters keep narrowing dabbrev results.

In order to fix this I modified cape-dabbrev to use another variable for minimum prefix length. If the prefix length for the completion would be shorter, it just returns nil. By setting it to 2, my completions worked as expected with dabbrev only showing after 2 characters and if the prior capf didn't have completions.

Alternatively, perhaps could add a capf wrapper that only returns results if the prefix is long enough.

If you would be interested in adding such functionality, I'd be willing to make a PR, but wanted to know before I go and try to figure out how to do the copyright assignment.

minad commented 2 years ago

I would accept a PR which adds a general minimum input capf wrapper. All such general functionality is ideally provided by wrappers since it may be useful in many scenarios.

minad commented 2 years ago

The wrapper can be used like this:

(setq completion-at-point-functions
      (list (cape-capf-prefix-length #'cape-dabbrev 2)))
jdtsmith commented 2 years ago

This looks generally useful, allowing you to enable "rare" CAPFs once prefix lengths are long. But wouldn't corfu-auto-prefix=2 also have worked in this instance?

minad commented 2 years ago

@jdtsmith I am not sure, but the idea of allowing different prefix lengths per capf has come up before in other Corfu issues.

accelbread commented 2 years ago

Thanks! Appreciate the update!

corfu-auto-prefix wasn't sufficient as I wanted the prior capf to work with 1 character; this fixes my issue though.