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

Re: env -u completion doesn't work when there is a command



Bart Schaefer wrote:
> On Jul 30,  8:00pm, Vincent Lefevre wrote:
> }
> }   env -u LIBR[TAB] gcc
> } 
> } where the cursor is after LIBR, the completion doesn't work.
> 
> This is a generalized problem with _arguments, in that there's no way
> to specify that an option (-u in this case) has a mandatory argument
> that must be in a separate word.

I'm not sure it's that, since using the specification
  '-u+:env var to remove:compadd ${(k)parameters[(R)*export*]}'
doesn't seem to fix it.  This should says that if there's no option
immediately after the -u there must be one in the next word, which would
cover the current case.

It seems comparguments -O is returning false, causing _arguments to
think there are no more arguments to complete.

comparguments is defined in zsh/computil and is documented thus:

       comparguments
              This  is  used by the _arguments function to do the argument and
              command line parsing.  Like compdescribe it has an option -i  to
              do  the  parsing  and initialize some internal state and various
              options to access the state information to decide what should be
              completed.

Right.  Slightly more helpfully, the code for comparguments -O says:

        /* This returns the descriptions for the options in the arrays whose
         * names are given as arguments.  The descriptions are strings in a
         * form usable by _describe.  The return value says if there are any
         * options to be completed. */

so I would guess this is looking at the wrong word to decide if there
are options to be completed, since we're getting to

      _tags "$subcs[@]"

at _arguments:219 instead of 

      _tags "$subcs[@]" options

at _arguments:217.  However, as that's the only comment it's hard to
tell.  Actually, "$subcs[@]" expands to argument-rest, so maybe it's
comparguments -D, which sets subcs, that's too blame.  The comment for
that says

        /* This returns the descriptions, actions and sub-contexts for the
         * things _arguments has to execute at this place on the line (the
         * sub-contexts are used as tags).
         * The return value is particularly important here, it says if 
         * there are arguments to completely at all. */

The argument-rest comes from ca_set_data(), an uncommented 91-line
function that does the guts of comparguments -D.  This uses the state
originally set up by comparguments -i, however.  comparguments -i calls
ca_parse_line() which has a few comments suggesting it might be
searching for options and arguments.  I think that might be the place to
start.  But who knows?

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



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