diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | Completion/Base/Utility/_values | 27 | ||||
-rw-r--r-- | Doc/Zsh/compsys.yo | 10 | ||||
-rw-r--r-- | Src/Zle/computil.c | 39 |
4 files changed, 58 insertions, 25 deletions
diff --git a/ChangeLog b/ChangeLog index 289b283aa..363e64c54 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2001-05-08 Sven Wischnowsky <wischnow@zsh.org> + + * 14257: Completion/Base/Utility/_values, Doc/Zsh/compsys.yo, + Src/Zle/computil.c: add -S option to specify separator between + values and their arguments; make _values add the + value-separator as a suffix for most types of actions + 2001-05-08 Oliver Kiddle <opk@zsh.org> * 14256: Completion/Zsh/Context/_subscript: fix minor mistake diff --git a/Completion/Base/Utility/_values b/Completion/Base/Utility/_values index cb90ed578..e074e1393 100644 --- a/Completion/Base/Utility/_values +++ b/Completion/Base/Utility/_values @@ -13,9 +13,12 @@ done if compvalues -i "$@"; then - local noargs args opts descr action expl sep subc + local noargs args opts descr action expl sep argsep subc test='*' local oldcontext="$curcontext" + compvalues -S argsep + compvalues -s sep && [[ -n "$sep" ]] && test="[^${(q)sep}]#" + if ! compvalues -D descr action; then _tags values || return 1 @@ -24,17 +27,17 @@ if compvalues -i "$@"; then compvalues -V noargs args opts - if [[ "$PREFIX" = *\=* ]]; then + if [[ "$PREFIX" = *${argsep}${~test} ]]; then local name - name="${PREFIX%%\=*}" + name="${PREFIX%%${argsep}*}" if compvalues -L "$name" descr action; then - IPREFIX="${IPREFIX}${name}=" - PREFIX="${PREFIX#*\=}" + IPREFIX="${IPREFIX}${name}${argsep}" + PREFIX="${PREFIX#*${argsep}}" else local prefix suffix - prefix="${PREFIX#*\=}" + prefix="${PREFIX#*${argsep}}" suffix="$SUFFIX" PREFIX="$name" SUFFIX='' @@ -45,7 +48,7 @@ if compvalues -i "$@"; then PREFIX="$prefix" SUFFIX="$suffix" - IPREFIX="${IPREFIX}${args[1]%%:*}=" + IPREFIX="${IPREFIX}${args[1]%%:*}${argsep}" compvalues -L "${args[1]%%:*}" descr action subc curcontext="${oldcontext%:*}:$subc" fi @@ -59,8 +62,8 @@ if compvalues -i "$@"; then _describe "$descr" \ noargs "$sep[@]" -M 'r:|[_-]=* r:|=*' -- \ - args -S= -M 'r:|[_-]=* r:|=*' -- \ - opts -qS= -M 'r:|[_-]=* r:|=*' + args -S "${argsep}" -M 'r:|[_-]=* r:|=*' -- \ + opts -qS "${argsep}" -M 'r:|[_-]=* r:|=*' curcontext="$oldcontext" @@ -82,7 +85,7 @@ if compvalues -i "$@"; then # we have only one possible value left. [[ ${#snames}+${#names}+${#onames} -ne 1 ]] && compvalues -s sep && - expl=( "-qS$sep" "$expl[@]" ) + expl=( "-qS$sep" "$expl[@]" ) sep=( "-qS$sep" ) if [[ "$action" = -\>* ]]; then compvalues -v val_args @@ -113,7 +116,7 @@ if compvalues -i "$@"; then eval ws\=\( "${action[3,-3]}" \) - _describe "$descr" ws -M 'r:|[_-]=* r:|=*' "$subopts[@]" + _describe "$descr" ws -M 'r:|[_-]=* r:|=*' "$subopts[@]" "$sep[@]" elif [[ "$action" = \(*\) ]]; then @@ -121,7 +124,7 @@ if compvalues -i "$@"; then eval ws\=\( "${action[2,-2]}" \) - _all_labels arguments expl "$descr" compadd "$subopts[@]" -a - ws + _all_labels arguments expl "$descr" compadd "$subopts[@]" "$sep[@]" -a - ws elif [[ "$action" = \{*\} ]]; then # A string in braces is evaluated. diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index 7e322aa9b..79574d321 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -3949,8 +3949,14 @@ listing the values. All other arguments describe the possible values and their arguments in the same format used for the description of options by the tt(_arguments) function (see above). The only differences are that -no minus or plus sign is required at the beginning and that -values can have only one argument. +no minus or plus sign is required at the beginning, that +values can have only one argument and that those forms of actions +beginning with an equal sign are not supported. + +The character separating a value from its argument can be set using the +option tt(-S) (like tt(-s), followed by the character to use as the +separator in the next argument). If this option is not used, the equal +sign will be used as the separator. Example: diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c index a4620151b..72ec4d9e6 100644 --- a/Src/Zle/computil.c +++ b/Src/Zle/computil.c @@ -2029,6 +2029,7 @@ struct cvdef { char *descr; /* global description */ int hassep; /* multiple values allowed */ char sep; /* separator character */ + char argsep; /* argument separator */ Cvdef next; /* next in cache */ Cvval vals; /* value definitions */ char **defs; /* original strings */ @@ -2090,16 +2091,21 @@ parse_cvdef(char *nam, char **args) Cvdef ret; Cvval val, *valp; Caarg arg; - char **oargs = args, sep = '\0', *name, *descr, *p, *q, **xor, c; + char **oargs = args, sep = '\0', asep = '=', *name, *descr, *p, *q, **xor, c; int xnum, multi, vtype, hassep = 0; - if (args[0][0] == '-' && args[0][1] == 's' && !args[0][2]) { + while (args[0][0] == '-' && (args[0][1] == 's' || args[0][1] == 'S') && + !args[0][2]) { if (args[1][0] && args[1][1]) { zwarnnam(nam, "invalid separator: %s", args[1], 0); return NULL; } - hassep = 1; - sep = args[1][0]; + if (args[0][1] == 's') { + hassep = 1; + sep = args[1][0]; + } else + asep = args[1][0]; + args += 2; } if (!args[0] || !args[1]) { @@ -2112,6 +2118,7 @@ parse_cvdef(char *nam, char **args) ret->descr = ztrdup(descr); ret->hassep = hassep; ret->sep = sep; + ret->argsep = asep; ret->next = NULL; ret->vals = NULL; ret->defs = zarrdup(oargs); @@ -2330,7 +2337,7 @@ cv_parse_word(Cvdef d) for (str = compprefix, end = strchr(str, d->sep); end;) { *end = '\0'; - if ((heq = !!(eq = strchr(str, '=')))) + if ((heq = !!(eq = strchr(str, d->argsep)))) *eq++ = '\0'; else eq = ""; @@ -2342,7 +2349,7 @@ cv_parse_word(Cvdef d) cv_inactive(d, ptr->xor); } if (heq) - eq[-1] = '='; + eq[-1] = d->argsep; *end = d->sep; str = end + 1; @@ -2357,7 +2364,7 @@ cv_parse_word(Cvdef d) if ((end = strchr(str, d->sep))) *end = '\0'; - if ((heq = !!(eq = strchr(str, '=')))) + if ((heq = !!(eq = strchr(str, d->argsep)))) *eq++ = '\0'; else eq = ""; @@ -2369,7 +2376,7 @@ cv_parse_word(Cvdef d) cv_inactive(d, ptr->xor); } if (heq) - eq[-1] = '='; + eq[-1] = d->argsep; if (end) *end++ = d->sep; } @@ -2408,16 +2415,16 @@ cv_parse_word(Cvdef d) compprefix = str; compsuffix = ztrdup(""); - if ((eq = strchr(str, '='))) { + if ((eq = strchr(str, d->argsep))) { *eq++ = '\0'; if ((ptr = cv_get_val(d, str)) && ptr->type != CVV_NOARG) { - eq[-1] = '='; + eq[-1] = d->argsep; ignore_prefix(eq - str); state.def = ptr->arg; state.val = ptr; } else - eq[-1] = '='; + eq[-1] = d->argsep; } memcpy(&cv_laststate, &state, sizeof(state)); } @@ -2445,6 +2452,7 @@ bin_compvalues(char *nam, char **args, char *ops, int func) case 'C': min = 1; max = 1; break; case 'V': min = 3; max = 3; break; case 's': min = 1; max = 1; break; + case 'S': min = 1; max = 1; break; case 'd': min = 1; max = 1; break; case 'L': min = 3; max = 4; break; case 'v': min = 1; max = 1; break; @@ -2546,6 +2554,15 @@ bin_compvalues(char *nam, char **args, char *ops, int func) return 0; } return 1; + case 'S': + { + char tmp[2]; + + tmp[0] = cv_laststate.d->argsep; + tmp[1] = '\0'; + setsparam(args[1], ztrdup(tmp)); + } + return 0; case 'd': setsparam(args[1], ztrdup(cv_laststate.d->descr)); return 0; |