[-- Attachment #1.1: Type: text/plain, Size: 421 bytes --] Hi, Others in the IRC hadn't experienced this bug so I'm asking here. In some cases, when I tab to open the menu everything is duplicated, see below for example [image: image.png] I've found this happens when my .zshrc contains > zstyle ':completion:*:matches' group 'yes' > zstyle ':completion:*' group-name '' > zstyle ":completion:*" list-dirs-first true > autoload -U compinit && compinit > > Best regards, Morten [-- Attachment #1.2: Type: text/html, Size: 1145 bytes --] [-- Attachment #2: image.png --] [-- Type: image/png, Size: 39189 bytes --]
On 6/23/22 05:54, Morten Nissov wrote:
> Hi,
>
> Others in the IRC hadn't experienced this bug so I'm asking here.
>
> In some cases, when I tab to open the menu everything is duplicated, see below for example
> image.png
> I've found this happens when my .zshrc contains
>
> |zstyle ':completion:*:matches' group 'yes' zstyle ':completion:*' group-name '' zstyle ":completion:*" list-dirs-first true autoload -U compinit && compinit
> |
>
>
> Best regards,
> Morten
Just the group-name and list-dirs-first styles being empty string and true are needed to cause the problem.
with ''python foo'' _python makes its way to _normal, returns (seemingly true) then compsys calls _default to
complete -default- for some reason that i am unsure of.
as a workaround disabling list-dirs-first for python would prevent the duplicates from happening:
zstyle ':completion::complete:python<->#(.<->)#::*' list-dirs-first false
but even with that, compsys seems to still tries to complete -default-.
On Thu, Jun 23, 2022 at 7:42 AM Eric Cook <llua@gmx.com> wrote: > > On 6/23/22 05:54, Morten Nissov wrote: > > In some cases, when I tab to open the menu everything is duplicated, see below for example > > Just the group-name and list-dirs-first styles being empty string and true are needed to cause the problem. There are some interacting things going on here. First, _python uses #compdef -P python[0-9.]# This means to first try completions for commands matching the pattern, and then try completions for any other context that matches, which in this case happens to be -default-. This is handled by _dispatch, which (after discovering that "python3" matches the pattern), sets _compskip=default to indicate that it should not try the -default- context after all, and then calls _python. Unfortunately _python calls _normal which sets _compskip='' again. _normal is expecting _compskip to have come from _main_complete, but instead it clobbers the local in _dispatch, so when control eventually returns there, _dispatch goes ahead with completing for -default-. This would be invisible except that list-dirs-first causes the results of these two different contexts to be placed in separate completion groups, and then group-name prevents them from being mutually de-duplicated. The trouble here is that the completion invoked by _dispatch is explicitly allowed to change _compskip to control the behavior of _dispatch. It just happens that any completion that relies on calling _normal may do so incorrectly. Now, as it happens there's an undocumented option of _normal to prevent it from doing this, but using that option breaks the python3 completion because the -default- context is needed for the "script argument". So the fix appears to be to make _compskip local to _python, which seems a bit icky because it doesn't help with any other completions that may have it wrong. Better suggestions? diff --git a/Completion/Unix/Command/_python b/Completion/Unix/Command/_python index e5bac18bb..2711b8fd3 100644 --- a/Completion/Unix/Command/_python +++ b/Completion/Unix/Command/_python @@ -3,7 +3,7 @@ # Python 2.7 # Python 3.9 -local curcontext="$curcontext" state state_descr line +local curcontext="$curcontext" state state_descr line _compskip="$_compskip" typeset -A opt_args local -a args
[-- Attachment #1: Type: text/plain, Size: 1405 bytes --] Regarding the workaround, as far as I can see `zstyle ':completion::complete:python<->#(.<->)#::*' list-dirs-first false` doesn't actually fix the problem. `zstyle ':completion::complete:python3::*' list-dirs-first false` does however, though obviously only for python3. Morten On Thu, Jun 23, 2022 at 4:42 PM Eric Cook <llua@gmx.com> wrote: > On 6/23/22 05:54, Morten Nissov wrote: > > Hi, > > > > Others in the IRC hadn't experienced this bug so I'm asking here. > > > > In some cases, when I tab to open the menu everything is duplicated, see > below for example > > image.png > > I've found this happens when my .zshrc contains > > > > |zstyle ':completion:*:matches' group 'yes' zstyle ':completion:*' > group-name '' zstyle ":completion:*" list-dirs-first true autoload -U > compinit && compinit > > | > > > > > > Best regards, > > Morten > > Just the group-name and list-dirs-first styles being empty string and true > are needed to cause the problem. > > with ''python foo'' _python makes its way to _normal, returns (seemingly > true) then compsys calls _default to > complete -default- for some reason that i am unsure of. > > as a workaround disabling list-dirs-first for python would prevent the > duplicates from happening: > zstyle ':completion::complete:python<->#(.<->)#::*' list-dirs-first false > > but even with that, compsys seems to still tries to complete -default-. > > [-- Attachment #2: Type: text/html, Size: 1969 bytes --]
On Fri, Jun 24, 2022 at 7:40 AM Morten Nissov <morten.c.nissov@gmail.com> wrote:
>
> Regarding the workaround, as far as I can see `zstyle ':completion::complete:python<->#(.<->)#::*' list-dirs-first false` doesn't actually fix the problem.
That's because the context being tested is actually
:completion::complete:python3:: which considered "shorter than" the
pattern above, so the :completion:* zstyle is chosen instead. The
rules for deciding what's the "best match" for zstyle patterns are a
bit convoluted. Leave off the final * and you can leave the
number-match for python version.
On Sat, Jun 25, 2022 at 10:15 PM Bart Schaefer
<schaefer@brasslantern.com> wrote:
>
> Leave off the final * and you can leave the
> number-match for python version.
Either of these also works:
# Leave out one colon
zstyle ':completion::complete:python<->#(.<->)#:*' list-dirs-first false
# Leave out the word "complete"
zstyle ':completion:*:python<->#(.<->)#::*' list-dirs-first false
[-- Attachment #1: Type: text/plain, Size: 836 bytes --] Hopefully it's not something on my end, but it looks as though none of the following works ether - zstyle ':completion::complete:python<->#(.<->)#::' list-dirs-first false - zstyle ':completion::complete:python<->#(.<->)#:*' list-dirs-first false - zstyle ':completion:*:python<->#(.<->)#::*' list-dirs-first false Morten On Sun, Jun 26, 2022 at 7:18 AM Bart Schaefer <schaefer@brasslantern.com> wrote: > On Sat, Jun 25, 2022 at 10:15 PM Bart Schaefer > <schaefer@brasslantern.com> wrote: > > > > Leave off the final * and you can leave the > > number-match for python version. > > Either of these also works: > > # Leave out one colon > zstyle ':completion::complete:python<->#(.<->)#:*' list-dirs-first false > > # Leave out the word "complete" > zstyle ':completion:*:python<->#(.<->)#::*' list-dirs-first false > [-- Attachment #2: Type: text/html, Size: 1495 bytes --]
On Thu, Jun 23, 2022 at 10:41 PM Bart Schaefer <schaefer@brasslantern.com> wrote: > > The trouble here is that the completion invoked by _dispatch is > explicitly allowed to change _compskip to control the behavior of > _dispatch. It just happens that any completion that relies on calling > _normal may do so incorrectly. > > [...] So the fix appears to be to make _compskip local to > _python, which seems a bit icky because it doesn't help with any other > completions that may have it wrong. Better suggestions? As there's been no follow-up, and this also appears to address issues raised in https://zsh.org/workers/45767, I'm going to go ahead and commit the change to _python.