From c9e0760f68994a0222f9b17d2c3f4ea0da337b98 Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Fri, 24 Mar 2000 00:53:26 +0000 Subject: manual/10204 --- Completion/Base/_arguments | 9 ++++++--- Completion/Base/_values | 9 ++++++--- Completion/Core/_alternative | 8 ++++++-- Completion/Core/_tags | 18 +++++++++++++++--- Completion/Core/_wanted | 4 ++-- Src/Zle/computil.c | 45 ++++++++++++++++++++++---------------------- 6 files changed, 58 insertions(+), 35 deletions(-) diff --git a/Completion/Base/_arguments b/Completion/Base/_arguments index 9a133617c..03f695629 100644 --- a/Completion/Base/_arguments +++ b/Completion/Base/_arguments @@ -236,14 +236,17 @@ if (( $# )) && comparguments -i "$autod" "$@"; then # A string in braces is evaluated. - _loop arguments expl "$descr" eval "$action[2,-2]" - + while _try arguments expl "$descr"; do + eval "$action[2,-2]" + done elif [[ "$action" = \ * ]]; then # If the action starts with a space, we just call it. eval "action=( $action )" - _loop arguments expl "$descr" "$action[@]" + while _try arguments expl "$descr"; do + "$action[@]" + done else # Otherwise we call it with the description-arguments. diff --git a/Completion/Base/_values b/Completion/Base/_values index 754147e05..e681d88ef 100644 --- a/Completion/Base/_values +++ b/Completion/Base/_values @@ -124,14 +124,17 @@ if compvalues -i "$@"; then # A string in braces is evaluated. - _loop arguments expl "$descr" eval "$action[2,-2]" - + while _try arguments expl "$descr"; do + eval "$action[2,-2]" + done elif [[ "$action" = \ * ]]; then # If the action starts with a space, we just call it. eval "action=( $action )" - _loop arguments expl "$descr" "$action[@]" + while _try arguments expl "$descr"; do + "$action[@]" + done else # Otherwise we call it with the description-arguments built above. diff --git a/Completion/Core/_alternative b/Completion/Core/_alternative index 482e9db51..3267ffeb7 100644 --- a/Completion/Core/_alternative +++ b/Completion/Core/_alternative @@ -50,13 +50,17 @@ while _tags; do # A string in braces is evaluated. - _loop "${def%%:*}" expl "$descr" eval "$action[2,-2]" + while _try "${def%%:*}" expl "$descr"; do + eval "$action[2,-2]" + done elif [[ "$action" = \ * ]]; then # If the action starts with a space, we just call it. eval "action=( $action )" - _loop "${def%%:*}" expl "$descr" "$action[@]" + while _try "${def%%:*}" expl "$descr"; do + "$action[@]" + done else # Otherwise we call it with the description-arguments built above. diff --git a/Completion/Core/_tags b/Completion/Core/_tags index b74e70264..2dfa56f9d 100644 --- a/Completion/Core/_tags +++ b/Completion/Core/_tags @@ -1,5 +1,17 @@ #autoload +local prev + +# A `--' as the first argument says that we should tell comptags to use +# the preceding function nesting level. This is only documented here because +# if everythings goes well, users won't have to worry about it and should +# not mess with it. + +if [[ "$1" = -- ]]; then + prev=- + shift +fi + if (( $# )); then # We have arguments: the tags supported in this context. @@ -33,7 +45,7 @@ if (( $# )); then # Set and remember offered tags. - comptags -i "$curcontext" "$@" + comptags "-i$prev" "$curcontext" "$@" # Sort the tags. @@ -80,11 +92,11 @@ if (( $# )); then # Return non-zero if at least one set of tags should be used. - comptags -T + comptags "-T$prev" return fi # The other mode: switch to the next set of tags. -comptags -N +comptags "-N$prev" diff --git a/Completion/Core/_wanted b/Completion/Core/_wanted index 1d6dcdb59..2303322d4 100644 --- a/Completion/Core/_wanted +++ b/Completion/Core/_wanted @@ -26,8 +26,8 @@ if [[ $# -gt 3 ]]; then return 1 fi elif [[ $# -gt 1 ]]; then - _tags "$targs[@]" "$1" && _comp_tags="$_comp_tags $1" && + _tags -- "$targs[@]" "$1" && _comp_tags="$_comp_tags $1" && _description "$gopt" "$@" else - _tags "$targs[@]" "$1" && _comp_tags="$_comp_tags $1" + _tags -- "$targs[@]" "$1" && _comp_tags="$_comp_tags $1" fi diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c index b96bc20d8..088d89931 100644 --- a/Src/Zle/computil.c +++ b/Src/Zle/computil.c @@ -2225,14 +2225,14 @@ freectags(Ctags t) /* Set the tags for the current local level. */ static void -settags(char **tags) +settags(int level, char **tags) { Ctags t; - if (comptags[locallevel]) - freectags(comptags[locallevel]); + if (comptags[level]) + freectags(comptags[level]); - comptags[locallevel] = t = (Ctags) zalloc(sizeof(*t)); + comptags[level] = t = (Ctags) zalloc(sizeof(*t)); t->all = zarrdup(tags + 1); t->context = ztrdup(*tags); @@ -2263,22 +2263,23 @@ arrcontains(char **a, char *s, int colon) static int bin_comptags(char *nam, char **args, char *ops, int func) { - int min, max, n; + int min, max, n, level; if (incompfunc != 1) { zwarnnam(nam, "can only be called from completion function", NULL, 0); return 1; } - if (args[0][0] != '-' || !args[0][1] || args[0][2]) { + if (args[0][0] != '-' || !args[0][1] || + (args[0][2] && (args[0][2] != '-' || args[0][3]))) { zwarnnam(nam, "invalid argument: %s", args[0], 0); return 1; } - if (locallevel >= MAX_TAGS) { + level = locallevel - (args[0][2] ? 1 : 0); + if (level >= MAX_TAGS) { zwarnnam(nam, "nesting level too deep", NULL, 0); return 1; } - if ((args[0][1] != 'i' && args[0][1] != 'A' && !comptags[locallevel]) || - (args[0][1] == 'A' && !comptags[lasttaglevel])) { + if (args[0][1] != 'i' && args[0][1] != 'I' && !comptags[level]) { zwarnnam(nam, "no tags registered", NULL, 0); return 1; } @@ -2304,39 +2305,39 @@ bin_comptags(char *nam, char **args, char *ops, int func) } switch (args[0][1]) { case 'i': - settags(args + 1); - lasttaglevel = locallevel; + settags(level, args + 1); + lasttaglevel = level; break; case 'C': - setsparam(args[1], ztrdup(comptags[locallevel]->context)); + setsparam(args[1], ztrdup(comptags[level]->context)); break; case 'T': - return !comptags[locallevel]->sets; + return !comptags[level]->sets; case 'N': { Ctset s; - if (comptags[locallevel]->init) - comptags[locallevel]->init = 0; - else if ((s = comptags[locallevel]->sets)) { - comptags[locallevel]->sets = s->next; + if (comptags[level]->init) + comptags[level]->init = 0; + else if ((s = comptags[level]->sets)) { + comptags[level]->sets = s->next; s->next = NULL; freectset(s); } - return !comptags[locallevel]->sets; + return !comptags[level]->sets; } case 'R': { Ctset s; - return !((s = comptags[locallevel]->sets) && + return !((s = comptags[level]->sets) && arrcontains(s->tags, args[1], 1)); } case 'A': { Ctset s; - if (comptags[lasttaglevel] && (s = comptags[lasttaglevel]->sets)) { + if (comptags[level] && (s = comptags[level]->sets)) { char **q, *v = NULL; int l = strlen(args[1]); @@ -2368,10 +2369,10 @@ bin_comptags(char *nam, char **args, char *ops, int func) return 1; } case 'S': - if (comptags[locallevel]->sets) { + if (comptags[level]->sets) { char **ret; - ret = zarrdup(comptags[locallevel]->sets->tags); + ret = zarrdup(comptags[level]->sets->tags); setaparam(args[1], ret); } else return 1; -- cgit 1.4.1