1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-02 22:11:54 +02:00

29820: _pick_variant -b to match builtin

This commit is contained in:
Peter Stephenson 2011-10-14 19:01:41 +00:00
parent c70e44c9bd
commit 8dc39360c9
4 changed files with 62 additions and 3 deletions

View file

@ -1,3 +1,9 @@
2011-10-14 Peter Stephenson <p.w.stephenson@ntlworld.com>
* 29820: Doc/Zsh/compsys.yo,
Completion/Base/Utility/_pick_variant: -b option to match
builtins.
2011-10-12 Mikael Magnusson <mikachu@gmail.com>
* 29815: Doc/Makefile.in: include mod_langinfo in documentation.
@ -15455,5 +15461,5 @@
*****************************************************
* This is used by the shell to define $ZSH_PATCHLEVEL
* $Revision: 1.5475 $
* $Revision: 1.5476 $
*****************************************************

View file

@ -6,7 +6,7 @@ local -A opts
(( $+_cmd_variant )) || typeset -gA _cmd_variant
zparseopts -D -A opts c: r:
zparseopts -D -A opts b: c: r:
: ${opts[-c]:=$words[1]}
while [[ $1 = *=* ]]; do
@ -19,6 +19,12 @@ if (( $+_cmd_variant[$opts[-c]] )); then
return 0
fi
if [[ $+opts[-b] -eq 1 && -n $builtins[$opts[-c]] ]]; then
_cmd_variant[$opts[-c]]=$opts[-b]
(( $+opts[-r] )) && eval "${opts[-r]}=${_cmd_variant[$opts[-c]]}"
return 0
fi
output="$(_call_program variant $opts[-c] "${@[2,-1]}" </dev/null 2>&1)"
for cmd pat in "$var[@]"; do

View file

@ -4387,7 +4387,9 @@ tt(ambiguous), tt(special-dirs), tt(list-suffixes) and tt(file-sort)
described above.
)
findex(_pick_variant)
item(tt(_pick_variant [ tt(-c) var(command) ] [ tt(-r) var(name) ] var(label)tt(=)var(pattern) ... var(label) [ var(args) ... ]))(
xitem(tt(_pick_variant) [ tt(-b) var(builtin-label) ] [ tt(-c)
var(command) ] [ tt(-r) var(name) ])
item( var(label)tt(=)var(pattern) ... var(label) [ var(args) ... ])(
This function is used to resolve situations where a single command name
requires more than one type of handling, either because it
has more than one variant or because there is a name clash between two
@ -4403,6 +4405,10 @@ tt(...)' contains var(pattern), then tt(label) is selected as the label
for the command variant. If none of the patterns match, the final
command label is selected and status 1 is returned.
If the `tt(-b) var(builtin-label)' is given, the command is tested to
see if it is provided as a shell builtin, possibly autoloaded; if so,
the label var(builtin-label) is selected as the label for the variant.
If the `tt(-r) var(name)' is given, the var(label) picked is stored in
the parameter named var(name).

View file

@ -1869,6 +1869,10 @@ get_comp_string(void)
}
} else if (p < curs) {
if (*p == Outbrace) {
/*
* HERE: strip and remember code from last
* comma to here.
*/
cant = 1;
break;
}
@ -1876,6 +1880,16 @@ get_comp_string(void)
char *tp = p;
if (!skipparens(Inbrace, Outbrace, &tp)) {
/*
* Balanced brace: skip.
* We only deal with unfinished braces, so
* something{foo<x>bar,morestuff}else
* doesn't work
*
* HERE: instead, continue, look for a comma.
* Stack tp and brace for popping when we
* find a comma at each level.
*/
i += tp - p - 1;
dp += tp - p - 1;
p = tp - 1;
@ -1918,10 +1932,16 @@ get_comp_string(void)
hascom = 1;
}
} else {
/* On or after the cursor position */
if (*p == Inbrace) {
char *tp = p;
if (!skipparens(Inbrace, Outbrace, &tp)) {
/*
* Balanced braces after the cursor.
* Could do the same with these as
* those before the cursor.
*/
i += tp - p - 1;
dp += tp - p - 1;
p = tp - 1;
@ -1932,6 +1952,14 @@ get_comp_string(void)
break;
}
if (p == curs) {
/*
* We've reached the cursor position.
* If there's a pending open brace at this
* point we need to stack the text.
* We've marked the bit we don't want from
* bbeg to bend, which might be a comma
* between the opening brace and us.
*/
if (bbeg) {
Brinfo new;
int len = bend - bbeg;
@ -1961,10 +1989,23 @@ get_comp_string(void)
bbeg = NULL;
}
if (*p == Comma) {
/*
* Comma on or after cursor.
* We set bbeg to NULL at the cursor; here
* it's being used to find the first comma
* afterwards.
*/
if (!bbeg)
bbeg = p;
hascom = 2;
} else if (*p == Outbrace) {
/*
* Closing brace on or after the cursor.
* Not sure how this can be after the cursor;
* if it was matched, wouldn't we have skipped
* over the group, and if it wasn't, surely we're
* not interested in it?
*/
Brinfo new;
int len;