mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-26 05:51:08 +02:00
fixes for _arguments with sets; make _zpty not use sets (11624)
This commit is contained in:
parent
7a3ca7a673
commit
a2750a4eff
5 changed files with 71 additions and 23 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
2000-05-29 Sven Wischnowsky <wischnow@zsh.org>
|
||||||
|
|
||||||
|
* 11624: Completion/Base/_arguments, Completion/Builtins/_zpty,
|
||||||
|
Doc/Zsh/compsys.yo, Src/Zle/computil.c: fixes for _arguments with
|
||||||
|
sets; make _zpty not use sets
|
||||||
|
|
||||||
2000-05-28 Bart Schaefer <schaefer@zsh.org>
|
2000-05-28 Bart Schaefer <schaefer@zsh.org>
|
||||||
|
|
||||||
* 11618: Completion/Base/_arguments: Fix bad shift.
|
* 11618: Completion/Base/_arguments: Fix bad shift.
|
||||||
|
|
|
@ -293,9 +293,9 @@ if (( $# )) && comparguments -i "$autod" "$@"; then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
shift "${#descrs} ? 1 : 0" descrs
|
shift descrs
|
||||||
shift "${#actions} ? 1 : 0" actions
|
shift actions
|
||||||
shift "${#subcs} ? 1 : 0" subcs
|
shift subcs
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ -z "$matched$hasopts" ]] && _requested options &&
|
if [[ -z "$matched$hasopts" ]] && _requested options &&
|
||||||
|
|
|
@ -3,19 +3,42 @@
|
||||||
local state line list names expl curcontext="$curcontext"
|
local state line list names expl curcontext="$curcontext"
|
||||||
typeset -A opt_args
|
typeset -A opt_args
|
||||||
|
|
||||||
|
|
||||||
_arguments -C -s \
|
_arguments -C -s \
|
||||||
'(-r)*::args:_normal' \
|
'(-r -w -L -d)-e[echo input characters]' \
|
||||||
- eb \
|
'(-r -w -L -d)-b[io to pseudo-terminal blocking]' \
|
||||||
'-e[echo input characters]' \
|
'(-r -w -L -e -b)-d[delete command]:*:name:->name' \
|
||||||
'-b[io to pseudo-terminal blocking]' \
|
'(-r -L -e -b -d)-w[send string to command]:name:->name:*:strings to write' \
|
||||||
- d \
|
'(: -r -w -e -b -d)-L[list defined commands as calls]' \
|
||||||
'-d[delete command]:*:name:->name' \
|
'(: -w -L -e -b -d)-r[read string from command]:name:->name:param: _parameters:pattern:' \
|
||||||
- w \
|
'(-r -w -L -d):zpty command name:' \
|
||||||
'-w[send string to command]:name:->name:*:strings to write' \
|
'(-r -w -L -d):cmd: _command_names -e' \
|
||||||
- L \
|
'(-r -w -L -d)*::args:_precommand' && return 0
|
||||||
'-L[list defined commands as calls]' \
|
|
||||||
- r \
|
# One could use sets, but that's more expensive and zpty is simple enough.
|
||||||
'(*)-r[read string from command]:name:->name:param:_parameters' && return 0
|
#
|
||||||
|
# _arguments -C -s \
|
||||||
|
# - read \
|
||||||
|
# '-r[read string from command]' \
|
||||||
|
# ':name:->name' \
|
||||||
|
# ':param: _parameters' \
|
||||||
|
# ':pattern:' \
|
||||||
|
# - write \
|
||||||
|
# '-w[send string to command]' \
|
||||||
|
# ':name:->name' \
|
||||||
|
# '*:strings to write' \
|
||||||
|
# - list \
|
||||||
|
# '-L[list defined commands as calls]' \
|
||||||
|
# - delete \
|
||||||
|
# '-d[delete command]' \
|
||||||
|
# '*:name:->name' \
|
||||||
|
# - start \
|
||||||
|
# '-e[echo input characters]' \
|
||||||
|
# '-b[io to pseudo-terminal blocking]' \
|
||||||
|
# ':zpty command name:' \
|
||||||
|
# ':cmd: _command_names -e' \
|
||||||
|
# '*::args:_precommand' && return 0
|
||||||
|
|
||||||
|
|
||||||
if [[ $state = name ]]; then
|
if [[ $state = name ]]; then
|
||||||
if ! zmodload -e zsh/zpty; then
|
if ! zmodload -e zsh/zpty; then
|
||||||
|
@ -26,8 +49,10 @@ if [[ $state = name ]]; then
|
||||||
names=( ${list%%:*} )
|
names=( ${list%%:*} )
|
||||||
if zstyle -T ":completion:${curcontext}" verbose; then
|
if zstyle -T ":completion:${curcontext}" verbose; then
|
||||||
zformat -a list ' --' ${${(f)"$(zpty)"}#*\) }
|
zformat -a list ' --' ${${(f)"$(zpty)"}#*\) }
|
||||||
_wanted names expl 'zpty command names' compadd -d list - "$names[@]"
|
_wanted names expl 'zpty command name' compadd -d list - "$names[@]"
|
||||||
else
|
else
|
||||||
_wanted names expl 'zpty command names' compadd - "$names[@]"
|
_wanted names expl 'zpty command name' compadd - "$names[@]"
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -2867,6 +2867,13 @@ options will be completed after the first non-option argument on the
|
||||||
line. With tt(-S), no option will be completed after a `tt(-)tt(-)' on
|
line. With tt(-S), no option will be completed after a `tt(-)tt(-)' on
|
||||||
the line and this argument will otherwise be ignored.
|
the line and this argument will otherwise be ignored.
|
||||||
|
|
||||||
|
Note that using multiple sets will be slower than using only one set
|
||||||
|
because the completion code has to parse the command line once for
|
||||||
|
every set. So more than one set should only be used if the command
|
||||||
|
syntax is too complicated. Note also that a option specification with
|
||||||
|
rest-arguments (as in `tt(-foo:*:...)' often allows to avoid the use
|
||||||
|
of multiple sets.
|
||||||
|
|
||||||
Another option supported is `tt(-O) var(name)'. The var(name) will be
|
Another option supported is `tt(-O) var(name)'. The var(name) will be
|
||||||
taken as the name of an array and its elements will be given to
|
taken as the name of an array and its elements will be given to
|
||||||
functions called to generate matches when executing the
|
functions called to generate matches when executing the
|
||||||
|
|
|
@ -510,7 +510,8 @@ parse_caarg(int mult, int type, int num, int opt, char *oname, char **def,
|
||||||
*p = ':';
|
*p = ':';
|
||||||
} else
|
} else
|
||||||
ret->action = ztrdup(rembslashcolon(p + 1));
|
ret->action = ztrdup(rembslashcolon(p + 1));
|
||||||
}
|
} else
|
||||||
|
ret->action = ztrdup("");
|
||||||
*def = p;
|
*def = p;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -588,7 +589,7 @@ parse_cadef(char *nam, char **args)
|
||||||
/* Now get the -s, -A, -S and -M options. */
|
/* Now get the -s, -A, -S and -M options. */
|
||||||
|
|
||||||
args++;
|
args++;
|
||||||
while ((p = *args) && *p == '-') {
|
while ((p = *args) && *p == '-' && p[1]) {
|
||||||
for (q = ++p; *q; q++)
|
for (q = ++p; *q; q++)
|
||||||
if (*q == 'M') {
|
if (*q == 'M') {
|
||||||
q = "";
|
q = "";
|
||||||
|
@ -1226,7 +1227,7 @@ ca_parse_line(Cadef d, int multi, int first)
|
||||||
Caopt ptr, wasopt, dopt;
|
Caopt ptr, wasopt, dopt;
|
||||||
struct castate state;
|
struct castate state;
|
||||||
char *line, *pe, **argxor = NULL;
|
char *line, *pe, **argxor = NULL;
|
||||||
int cur, doff, argend;
|
int cur, doff, argend, arglast;
|
||||||
Patprog endpat = NULL;
|
Patprog endpat = NULL;
|
||||||
|
|
||||||
/* Free old state. */
|
/* Free old state. */
|
||||||
|
@ -1284,7 +1285,7 @@ ca_parse_line(Cadef d, int multi, int first)
|
||||||
line; line = compwords[cur++]) {
|
line; line = compwords[cur++]) {
|
||||||
ddef = adef = NULL;
|
ddef = adef = NULL;
|
||||||
dopt = NULL;
|
dopt = NULL;
|
||||||
doff = state.singles = 0;
|
doff = state.singles = arglast = 0;
|
||||||
|
|
||||||
if (ca_inactive(d, argxor, cur, 0) ||
|
if (ca_inactive(d, argxor, cur, 0) ||
|
||||||
((d->flags & CDF_SEP) && !strcmp(line, "--"))) {
|
((d->flags & CDF_SEP) && !strcmp(line, "--"))) {
|
||||||
|
@ -1423,6 +1424,7 @@ ca_parse_line(Cadef d, int multi, int first)
|
||||||
if ((d->flags & CDF_ARG) && ca_inactive(d, NULL, cur + 1, 1))
|
if ((d->flags & CDF_ARG) && ca_inactive(d, NULL, cur + 1, 1))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
arglast = 1;
|
||||||
if (state.inopt) {
|
if (state.inopt) {
|
||||||
state.inopt = 0;
|
state.inopt = 0;
|
||||||
state.nargbeg = cur - 1;
|
state.nargbeg = cur - 1;
|
||||||
|
@ -1434,7 +1436,11 @@ ca_parse_line(Cadef d, int multi, int first)
|
||||||
(state.def->type == CAA_RREST ||
|
(state.def->type == CAA_RREST ||
|
||||||
state.def->type == CAA_RARGS)) {
|
state.def->type == CAA_RARGS)) {
|
||||||
state.inrest = 0;
|
state.inrest = 0;
|
||||||
state.opt = (cur == state.nargbeg + 1);
|
state.opt = (cur == state.nargbeg + 1 &&
|
||||||
|
(!*line ||
|
||||||
|
((*line == '-' || *line == '+') &&
|
||||||
|
(!line[1] ||
|
||||||
|
(*line == '-' && line[1] == '-' && !line[2])))));
|
||||||
state.optbeg = state.nargbeg;
|
state.optbeg = state.nargbeg;
|
||||||
state.argbeg = cur - 1;
|
state.argbeg = cur - 1;
|
||||||
state.argend = argend;
|
state.argend = argend;
|
||||||
|
@ -1510,6 +1516,10 @@ ca_parse_line(Cadef d, int multi, int first)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ca_laststate.def = adef;
|
ca_laststate.def = adef;
|
||||||
|
ca_laststate.opt = (!arglast || !*line ||
|
||||||
|
((*line == '-' || *line == '+') &&
|
||||||
|
(!line[1] ||
|
||||||
|
(*line == '-' && line[1] == '-' && !line[2]))));
|
||||||
ca_laststate.ddef = NULL;
|
ca_laststate.ddef = NULL;
|
||||||
ca_laststate.dopt = NULL;
|
ca_laststate.dopt = NULL;
|
||||||
ca_laststate.optbeg = state.nargbeg;
|
ca_laststate.optbeg = state.nargbeg;
|
||||||
|
@ -1801,7 +1811,7 @@ bin_comparguments(char *nam, char **args, char *ops, int func)
|
||||||
for (; lstate; lstate = lstate->snext) {
|
for (; lstate; lstate = lstate->snext) {
|
||||||
if (lstate->actopts &&
|
if (lstate->actopts &&
|
||||||
(lstate->opt || (lstate->doff && lstate->def) ||
|
(lstate->opt || (lstate->doff && lstate->def) ||
|
||||||
(lstate->def &&
|
(lstate->def && lstate->def->opt &&
|
||||||
(lstate->def->type == CAA_OPT ||
|
(lstate->def->type == CAA_OPT ||
|
||||||
(lstate->def->type >= CAA_RARGS &&
|
(lstate->def->type >= CAA_RARGS &&
|
||||||
lstate->def->num < 0)))) &&
|
lstate->def->num < 0)))) &&
|
||||||
|
|
Loading…
Reference in a new issue