zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Eric Cook <llua@gmx.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: Duplicate results in _python - (Re: [MINOR BUG] Duplicate results in tab-menu)
Date: Thu, 23 Jun 2022 22:41:40 -0700	[thread overview]
Message-ID: <CAH+w=7YMMDPTTBiVshGuG0_2fO0hU5Twf23Qcw-eRg_FJrFrcg@mail.gmail.com> (raw)
In-Reply-To: <0c939d76-d9ff-e684-cbc5-70dac285491d@gmx.com>

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


  reply	other threads:[~2022-06-24  5:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-23  9:54 [MINOR BUG] Duplicate results in tab-menu Morten Nissov
2022-06-23 14:42 ` Duplicate results in _python - (Re: [MINOR BUG] Duplicate results in tab-menu) Eric Cook
2022-06-24  5:41   ` Bart Schaefer [this message]
2022-07-17  3:48     ` Bart Schaefer
2022-06-24 14:40   ` Morten Nissov
2022-06-26  5:15     ` Bart Schaefer
2022-06-26  5:18       ` Bart Schaefer
2022-06-27  8:00         ` Morten Nissov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7YMMDPTTBiVshGuG0_2fO0hU5Twf23Qcw-eRg_FJrFrcg@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=llua@gmx.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).