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

Re: PATCH: completion



In article <199908230932.LAA02718@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
  Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx> writes:

> I don't agree here -- do you know of any command that accepts a `--'
> option which gets its argument in the next word? If so, I think that
> command shouldn't do that.

GNU getopt_long supports the style.

getopt_long(3):

       The getopt_long() function works like getopt() except that
       it  also  accepts long options, started out by two dashes.
       Long option names may be abbreviated if  the  abbreviation
       is unique or is an exact match for some defined option.  A
       long option may take a parameter, of the form  --arg=param
       or --arg param.

So, many GNU commands accept that.

> (I think you mean completion functions, the term `completer' refers to 
> those top-level thingies like `_complete'.)

Wow.  Yes.

> No, it shouldn't -- there is one string resulting from the expansion,
> even it is the empty string.

I see.

> What exactly doesn't work with single-letter option because of this?
> (I'm a bit too lazy to search ;-) I guess that this can be avoided by
> adding a ${...:#} somewhere.

Z(2):akr@is27e1u11% Src/zsh -f
is27e1u11% bindkey -e; fpath=($PWD/Completion/*(/)); autoload -U compinit; compinit -D; compdef _tst tst
is27e1u11% compconf group_matches=yes
is27e1u11% compconf message_format='%d'
is27e1u11% compconf description_format='%d'
is27e1u11% _tst () { _arguments -s '-a' '-b' }
is27e1u11% set -x
is27e1u11% tst -a<TAB>
...
+_arguments:370> unset opts[-a] dopts[] odopts[]
...
+_arguments:385> compadd -J option -X option -Q -y ( -b   ) - -ab -a -a
...
option
-b   

It should complete "b" immediately.

This is because "-a" in compadd arguments. It is the result of
expansion of "dopts[${(@)^dopts[(I)${ws[1][1]}[$uns]]}]" and
"odopts[${(@)^odopts[(I)${ws[1][1]}[$uns]]}]".

Z(2):akr@is27e1u11% Src/zsh -f
is27e1u11% typeset -A opts
is27e1u11% opts[-a]=
is27e1u11% opts[-b]=
is27e1u11% print -lr - "A${(@)^opts[(I)xx]}B"
AB
is27e1u11% print -lr - "A${${(@)^opts[(I)xx]}:#}B"
AB
is27e1u11% print -lr - "A${(@)${(@)^opts[(I)xx]}:#}B" 
AB
is27e1u11% 

Hm.
-- 
Tanaka Akira



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