Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Completion: How to show description for current option?



On Wed, Sep 1, 2021 at 3:23 AM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> On Tue, Aug 31, 2021 at 10:22 AM Bart Schaefer
> <schaefer@xxxxxxxxxxxxxxxx> wrote:
> >
> > That might be all that's needed; a matcher-list entry that allows '-'
> > to become '--'.  But I suspect there's something deeper going on in
> > the _git suite.
>
> Indeed, the _git suite of functions almost always use _alternative,
> which calls _describe with a hardcoded matcher which is prefixed to
> whatever appears in the matcher_list style.  On line 41 of
> _alternative:
>
> _describe -t "${def%%:*}" "$descr" ws -M 'r:|[_-]=* r:|=*' "$subopts[@]"
>
> I believe that makes it impossible to write a matcher-list zstyle that
> will swap out "-" with "--" in the context where Marlon wants it.  Can
> someone demonstrate a workaround?

Thank you all, but unfortunately, none of this is addressing the
actual problems I'm trying to solve. Let me try to rephrase:

# Problem number 1
When I type, for example,
    git switch -c^D
then completion shows me only
    -c
instead of
    -c             create and switch to a new
I would like to be able to see the description to check if I'm
actually using the right option.

# Problem number 2
When I type, for example,
    git switch -c^D
then completion shows me only
    -c
_even if_ I have a matcher (of which the details are not important for
this question) that would actually also match --conflict and --create.

The problem is not in the _git completer (I'm just using `git switch
-c` as an example here) nor in my matchers; the problem is in
_arguments. For whatever reason, if there is a single option that
matches exactly, _arguments decides not to print any description for
it _and_ also refuses to complete any other matching options at that
point.

Is there a way around this? Or have I run into an _arguments bug? The
relevant code can be found on lines 489 - 525:

        if [[ -z "$alwopt" || -z "$tried" || "$alwopt" = arg ]] &&
           comparguments -s single; then

          if [[ "$single" = direct ]]; then
            _all_labels options expl option \
        compadd -QS '' - "${PREFIX}${SUFFIX}"
          elif [[ -z "$optarg" && "$single" = next ]]; then
            _all_labels options expl option \
        compadd -Q - "${PREFIX}${SUFFIX}"
          elif [[ "$single" = equal ]]; then
            _all_labels options expl option \
        compadd -QqS= - "${PREFIX}${SUFFIX}"
          else

    tmp1=( "$next[@]" "$direct[@]" "$odirect[@]" "$equal[@]" )

            [[ "$PREFIX" = [-+]* ]] && tmp1=( "${(@M)tmp1:#${PREFIX[1]}*}" )

            [[ "$single" = next ]] &&
                tmp1=( "${(@)tmp1:#[-+]${PREFIX[-1]}((#e)|:*)}" )

    [[ "$PREFIX" != --* ]] && tmp1=( "${(@)tmp1:#--*}" )
    tmp3=( "${(M@)tmp1:#[-+]?[^:]*}" )
    tmp1=( "${(M@)tmp1:#[-+]?(|:*)}" )
    tmp2=( "${PREFIX}${(@M)^${(@)${(@)tmp1%%:*}#[-+]}:#?}" )

            _describe -O option \
                      tmp1 tmp2 -Q -S '' -- \
      tmp3 -Q

            [[ -n "$optarg" && "$single" = next && nm -eq
$compstate[nmatches] ]] &&
                _all_labels options expl option \
            compadd -Q - "${PREFIX}${SUFFIX}"

          fi
          single=yes




Messages sorted by: Reverse Date, Date, Thread, Author