* [BUG] Incorrect usage of $PREFIX and $SUFFIX in completion functions
@ 2024-04-09 7:27 Marlon Richert
2024-04-09 9:14 ` Oliver Kiddle
0 siblings, 1 reply; 3+ messages in thread
From: Marlon Richert @ 2024-04-09 7:27 UTC (permalink / raw)
To: Zsh hackers list
[-- Attachment #1: Type: text/plain, Size: 924 bytes --]
Many completion functions in the Zsh code base use $PREFIX$SUFFIX to get
the word to complete on the command line. However, this seems incorrect to
me, because it prevents the _prefix completer from functioning correctly
for those completion functions.
Shouldn't all completion functions simply use $PREFIX to get the word to
complete, since it is the responsibility of the completer function
(_complete, _prefix, etc.) to decide whether the character to the right
should be considered part of the word to be completed?
Shouldn't _complete do `PREFIX+=$SUFFIX; SUFFIX=` before calling completion
functions, since, otherwise, there is no meaningful difference between it
and _prefix?
Additionally, if _complete should indeed do `PREFIX+=$SUFFIX; SUFFIX=`,
then shouldn't compinit always enable COMPLETE_IN_WORD, since, without it,
_prefix is not able to function correctly and _complete should behave the
same regardless?
[-- Attachment #2: Type: text/html, Size: 1534 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [BUG] Incorrect usage of $PREFIX and $SUFFIX in completion functions
2024-04-09 7:27 [BUG] Incorrect usage of $PREFIX and $SUFFIX in completion functions Marlon Richert
@ 2024-04-09 9:14 ` Oliver Kiddle
2024-06-25 5:01 ` Marlon Richert
0 siblings, 1 reply; 3+ messages in thread
From: Oliver Kiddle @ 2024-04-09 9:14 UTC (permalink / raw)
To: Marlon Richert; +Cc: Zsh hackers list
Marlon Richert wrote:
> Many completion functions in the Zsh code base use $PREFIX$SUFFIX to get the
> word to complete on the command line. However, this seems incorrect to me,
> because it prevents the _prefix completer from functioning correctly for those
> completion functions.
If it is being used to get the word to complete then it is wrong. In
some complex cases, it may be a necessary compromise. There are also
cases where $words[CURRENT] is used (wrongly) instead of $PREFIX.
However, most cases of $PREFIX$SUFFIX found in a search of the functions
look valid at a brief glance. Note that, e.g.
[[ $PREFIX$SUFFIX = */* ]]
is equivalent to doing
[[ $PREFIX = */* || $SUFFIX = */* ]]
> Shouldn't all completion functions simply use $PREFIX to get the word to
> complete, since it is the responsibility of the completer function (_complete,
> _prefix, etc.) to decide whether the character to the right should be
> considered part of the word to be completed?
Depends on what exactly you mean by "word to complete". It is best
to leave matching up to the completion system so that it can handle
matching control etc correctly. There are cases where generating matches
is faster if you let the external tools filter by prefix. This is also
not uncommon in completions that have been converted from bash (which
isn't really the case for any included with zsh).
> 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.
Oliver
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [BUG] Incorrect usage of $PREFIX and $SUFFIX in completion functions
2024-04-09 9:14 ` Oliver Kiddle
@ 2024-06-25 5:01 ` Marlon Richert
0 siblings, 0 replies; 3+ messages in thread
From: Marlon Richert @ 2024-06-25 5:01 UTC (permalink / raw)
To: Oliver Kiddle; +Cc: Zsh hackers list
[-- Attachment #1: Type: text/plain, Size: 1760 bytes --]
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>,
* if complete_in_word is set, then
* _complete offers completions matching <prefix><anything><suffix>
* _prefix offers completions matching <prefix><anything>
* if complete_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.
[-- Attachment #2: Type: text/html, Size: 7879 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-06-25 5:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-09 7:27 [BUG] Incorrect usage of $PREFIX and $SUFFIX in completion functions Marlon Richert
2024-04-09 9:14 ` Oliver Kiddle
2024-06-25 5:01 ` Marlon Richert
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).