From 15996aeeecedf3b94447213ea4c473650cf8afb4 Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Wed, 16 Feb 2000 10:57:11 +0000 Subject: zsh-workers/9759 --- Completion/Base/_default | 20 ++++++++++---------- Doc/Zsh/compsys.yo | 17 +++++++++++++++++ Src/Zle/comp.h | 3 ++- Src/Zle/compcore.c | 6 ++++++ Src/Zle/compctl.c | 9 +++++++++ Src/Zle/complete.c | 1 + 6 files changed, 45 insertions(+), 11 deletions(-) diff --git a/Completion/Base/_default b/Completion/Base/_default index 8329a0358..b84cbff6a 100644 --- a/Completion/Base/_default +++ b/Completion/Base/_default @@ -1,16 +1,16 @@ #compdef -default- -# You can first try the `compctl's by uncommenting the `compcall' line -# below. -# This is without first (-T) and default (-D) completion. If you want -# them add `-T' and/or `-D' to this command. If there is a `compctl' -# for the command we are working on, we return immediatly. If you want -# to use new style completion anyway, remove the `|| return'. Also, -# you may want to use new style completion if the `compctl' didn't -# produce any matches. In that case remove the `|| return' and insert -# the line `[[ compstate[nmatches] -eq 0 ]] || return' after `compcall'. +local ctl -# compcall || return 0 +if { zstyle -s ':completion:${curcontext}:' use-compctl ctl || + zmodload -e zsh/compctl } && [[ "$ctl" != (no|false|0|off) ]]; then + local opt + + opt=() + [[ "$ctl" = *first* ]] && opt=(-T) + [[ "$ctl" = *default* ]] && opt=("$opt[@]" -D) + compcall "$opt[@]" || return 0 +fi _tags files || return 1 diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index f7b7f41d0..bbef94900 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -1359,6 +1359,23 @@ values), tt(options), tt(globbed-files), tt(directories) and tt(all-files) plus all tags offered by the completion function will be used. ) +item(tt(use-compctl))( +If this style is set to a string not equal to tt(false), tt(0), +tt(no), and tt(off), the completion system will use any completion +specifications defined with the tt(compctl) builtin command. If the +style is unset, this will only be done if the tt(zsh/compctl) module +is loaded. The string may also contain the substring tt(first) to make +the definition for tt(compctl -T) be used and the substring +tt(default) to make the one for tt(compctl -D) be used. + +Note that this is only intended to smooth the transition from +tt(compctl) to the new completion system and may disappear in the +future. + +Note also, that the definitions from tt(compctl) will only be used if +there is no special completion function for the command completion is +done upon. +) item(tt(users))( This may be set to a list of names that should be completed whenever a username is needed. If it is not set or the string on the line diff --git a/Src/Zle/comp.h b/Src/Zle/comp.h index f318b4049..9f2fb359a 100644 --- a/Src/Zle/comp.h +++ b/Src/Zle/comp.h @@ -364,7 +364,8 @@ typedef void (*CLPrintFunc)(Cmgroup, Cmatch *, int, int, int, int, #define INSERTMATCHHOOK (comphooks + 0) #define MENUSTARTHOOK (comphooks + 1) #define COMPCTLMAKEHOOK (comphooks + 2) -#define COMPLISTMATCHESHOOK (comphooks + 3) +#define COMPCTLCLEANUPHOOK (comphooks + 3) +#define COMPLISTMATCHESHOOK (comphooks + 4) /* compctl hook data struct */ diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c index feadfa3b1..0908fb120 100644 --- a/Src/Zle/compcore.c +++ b/Src/Zle/compcore.c @@ -844,6 +844,9 @@ makecomplist(char *s, int incmd, int lst) callcompfunc(s, compfunc); endcmgroup(NULL); + /* Needed for compcall. */ + runhookdef(COMPCTLCLEANUPHOOK, NULL); + if (oldlist) { nmatches = onm; validlist = 1; @@ -892,6 +895,9 @@ makecomplist(char *s, int incmd, int lst) dat.lst = lst; runhookdef(COMPCTLMAKEHOOK, (void *) &dat); + /* Needed for compcall. */ + runhookdef(COMPCTLCLEANUPHOOK, NULL); + return dat.lst; } } diff --git a/Src/Zle/compctl.c b/Src/Zle/compctl.c index 2f2e298e6..f3673df52 100644 --- a/Src/Zle/compctl.c +++ b/Src/Zle/compctl.c @@ -1892,6 +1892,13 @@ ccmakehookfn(Hookdef dummy, struct ccmakedat *dat) return 0; } +static int +cccleanuphookfn(Hookdef dummy, void *dat) +{ + ccused = ccstack = NULL; + return 0; +} + /* This adds a match to the list of matches. The string to add is given * * in s, the type of match is given in the global variable addwhat and * * the parameter t (if not NULL) is a pointer to a hash node node which * @@ -3906,6 +3913,7 @@ int boot_(Module m) { addhookfunc("compctl_make", (Hookfn) ccmakehookfn); + addhookfunc("compctl_cleanup", (Hookfn) cccleanuphookfn); return (addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)) != 1); } @@ -3914,6 +3922,7 @@ int cleanup_(Module m) { deletehookfunc("compctl_make", (Hookfn) ccmakehookfn); + deletehookfunc("compctl_cleanup", (Hookfn) cccleanuphookfn); deletebuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)); return 0; } diff --git a/Src/Zle/complete.c b/Src/Zle/complete.c index 70f95fd0f..e28a67cd4 100644 --- a/Src/Zle/complete.c +++ b/Src/Zle/complete.c @@ -1288,6 +1288,7 @@ struct hookdef comphooks[] = { HOOKDEF("insert_match", NULL, HOOKF_ALL), HOOKDEF("menu_start", NULL, HOOKF_ALL), HOOKDEF("compctl_make", NULL, 0), + HOOKDEF("compctl_cleanup", NULL, 0), HOOKDEF("comp_list_matches", ilistmatches, 0), }; -- cgit 1.4.1