On Tue, Apr 9, 2024 at 12:14 PM Oliver Kiddle <opk@zsh.org> wrote:
Marlon Richert wrote:
> Shouldn't _complete do `PREFIX+=$SUFFIX; SUFFIX=` before calling completion
> functions, since, otherwise, there is no meaningful difference between it and
> _prefix?

Definitely not. Given a<cursor>c and candidate matches abc and acd,
_complete should complete to abc with complete_in_word set, offer both with
_prefix and complete to acd if complete_in_word is unset.

I did some testing and it actually works slightly differently.

Given candidate matches abc, abcd and acd,

  * when given a<cursor>c,

    * if complete_in_word is set, then
      * _complete completes to abc and
      * _prefix is never called.

    * if complete_in_word is unset, then
      * _complete completes to acd and
      * _prefix is never called.

  * when given a<cursor>e,

    * if complete_in_word is set, then
      * _complete fails and
      * _prefix offers abc, abcd acd.

    * if complete_in_word is unset, then
      * _complete fails and
      * _prefix fails, too.

In other words, given a command line <prefix><cursor><suffix>,

* icomplete_in_word is set, then
  * _complete offers completions matching <prefix><anything><suffix>
  * _prefix offers completions matching <prefix><anything>

* icomplete_in_word is unset, then
  * _complete offers completions matching <prefix><suffix><anything>
  * _prefix also offers completions matching <prefix><suffix><anything>

I suppose that's actually what it says on the tin, but it sure didn't come to me intuitively.

I'm also still not sure whether all completion functions are using $PREFIX and $SUFFIX correctly, but I'll leave it at that.