From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27178 invoked from network); 29 May 2007 14:10:47 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.0 (2007-05-01) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00 autolearn=no version=3.2.0 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 29 May 2007 14:10:47 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 92264 invoked from network); 29 May 2007 14:10:41 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 29 May 2007 14:10:41 -0000 Received: (qmail 25519 invoked by alias); 29 May 2007 14:10:37 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 23485 Received: (qmail 25510 invoked from network); 29 May 2007 14:10:36 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 29 May 2007 14:10:36 -0000 Received: (qmail 91871 invoked from network); 29 May 2007 14:10:36 -0000 Received: from cluster-d.mailcontrol.com (217.69.20.190) by a.mx.sunsite.dk with SMTP; 29 May 2007 14:10:31 -0000 Received: from cameurexb01.EUROPE.ROOT.PRI ([62.189.241.200]) by rly50d.srv.mailcontrol.com (MailControl) with ESMTP id l4TE8XVB013278 for ; Tue, 29 May 2007 15:10:24 +0100 Received: from news01.csr.com ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.1830); Tue, 29 May 2007 15:10:10 +0100 Received: from news01.csr.com (localhost.localdomain [127.0.0.1]) by news01.csr.com (8.13.8/8.13.4) with ESMTP id l4TEAASF014184 for ; Tue, 29 May 2007 15:10:10 +0100 Received: from csr.com (pws@localhost) by news01.csr.com (8.13.8/8.13.8/Submit) with ESMTP id l4TEAAOV014181 for ; Tue, 29 May 2007 15:10:10 +0100 Message-Id: <200705291410.l4TEAAOV014181@news01.csr.com> X-Authentication-Warning: news01.csr.com: pws owned process doing -bs To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: PATCH: a couple more feature things Date: Tue, 29 May 2007 15:10:10 +0100 From: Peter Stephenson X-OriginalArrivalTime: 29 May 2007 14:10:10.0834 (UTC) FILETIME=[11A68F20:01C7A1FB] Content-Type: text/plain MIME-Version: 1.0 X-Scanned-By: MailControl A-07-07-05 (www.mailcontrol.com) on 10.68.0.160 1. Re-implement autoload slightly better to take account of features. After my previous patch "zmodload -F zsh/foo" would load the module zsh/foo but not turn on any features. This screwed up any features marked for autoloading from it. I've fixed it so that autoloads all issue a specific feature request, rather than just a request to load a module. This makes autoloads work better with features than I'd been expecting; we don't need to make autoloads force every feature to be enabled. As each needed autoload is encountered, that feature alone is turned on at that point. This should make the transition to use : syntax very smooth. 2. Basic completion for features. I decided it was too fraught to load a module to query the features if it wasn't already loaded. One problem is that if you load the module and unload it again all autoloads against the module are cancelled. This can probably be done better, given the previous fix. We can keep the autoload records around and regenerate them if the module is unloaded (or, perhaps better, if the feature is disabled). I'm not quite sure how useful this is, however. (The first argument of require_module isn't needed and should be removed. I'm assuming that with the changes to the module API trying to retain compatibility at this point is pointless.) Index: Completion/Zsh/Command/_zmodload =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Command/_zmodload,v retrieving revision 1.1 diff -u -r1.1 _zmodload --- Completion/Zsh/Command/_zmodload 2 Apr 2001 11:33:40 -0000 1.1 +++ Completion/Zsh/Command/_zmodload 29 May 2007 14:00:19 -0000 @@ -1,48 +1,70 @@ #compdef zmodload -local suf comp state line expl curcontext="$curcontext" ret=1 +local suf comp state line expl curcontext="$curcontext" ret=1 NORMARG typeset -A opt_args suf=() -_arguments -C -A "-*" -s \ - '(-d -e)-i[suppress error if command would do nothing]' \ +_arguments -n -C -A "-*" -s \ + '(-i -u -d -a -b -c -I -p -f -e)-A[create module aliases]' \ '-u[unload module]' \ - '(-i)-d[list or specify module dependencies]' \ '(-e)-a[autoload module]' \ '(-c -I -p -f)-b[autoload module for builtins]' \ '(-b -I -p -f)-c[autoload module for condition codes]' \ - '(-b -c -p -f)-I[define infix condition names]' \ - '(-b -c -I -f)-p[autoload module for parameters]' \ - '(-b -c -I -p)-f[autoload module for math functions]' \ + '(-i)-d[list or specify module dependencies]' \ '(-i -u -d -a -b -c -p -f -L -A)-e[test if modules are loaded]' \ + '(-b -c -I -p)-f[autoload module for math functions]' \ + '(-u -b -c -p -f -A)-F[handle features]' \ + '(-d -e)-i[suppress error if command would do nothing]' \ + '(-b -c -p -f)-I[define infix condition names]' \ + '(-u -b -c -p -f -A)-l[list features]' \ '(-e -u)-L[output in the form of calls to zmodload]' \ - '(-i -u -d -a -b -c -I -p -f -e)-A[create module aliases]' \ + '(-b -c -I -f)-p[autoload module for parameters]' \ + '(-u -b -c -p -f -A)-P[array param for features]:array name:_parameters' \ '*:params:->params' && ret=0 [[ $state = params ]] || return ret (( $+opt_args[-A] )) && compset -P '*=' || suf=( -S '=' ) -comp=( files aliases ) -if (( $+opt_args[-u] )); then - if (( $+opt_args[-b] || $+opt_args[-a] )); then - comp=( builtins ) + +if (( $+opt_args[-F] && CURRENT > NORMARG )); then + local module=$words[NORMARG] + local -a features + + if [[ $modules[$module] != loaded ]]; then + _message "features for unloaded module" else - comp=( loadedmodules aliases ) + zmodload -lFP features $module + if compset -P -; then + # only enabled features needed + features=(${${features:#-*}##?}) + elif compset -P +; then + # only disabled features needed + features=(${${features:#+*}##?}) + fi + _wanted features expl feature compadd -a features fi -fi -(( $+opt_args[-a] && CURRENT > 3 )) && comp=( builtins ) - -_tags "$comp[@]" -while _tags; do - _requested builtins expl 'builtin command' \ - compadd "$@" -k builtins && ret=0 - _requested loadedmodules expl 'loaded modules' \ - compadd -k 'modules[(R)loaded]' && ret=0 - _requested files expl 'module file' \ - _files -W module_path -/g '*.(dll|s[ol])(:r)' && ret=0 - _requested aliases expl 'module alias' \ - compadd "$suf[@]" -k 'modules[(R)alias*]' && ret=0 -done +else + comp=( files aliases ) + if (( $+opt_args[-u] )); then + if (( $+opt_args[-b] || $+opt_args[-a] )); then + comp=( builtins ) + else + comp=( loadedmodules aliases ) + fi + fi + (( $+opt_args[-a] && CURRENT > 3 )) && comp=( builtins ) -return ret + _tags "$comp[@]" + while _tags; do + _requested builtins expl 'builtin command' \ + compadd "$@" -k builtins && ret=0 + _requested loadedmodules expl 'loaded modules' \ + compadd -k 'modules[(R)loaded]' && ret=0 + _requested files expl 'module file' \ + _files -W module_path -/g '*.(dll|s[ol])(:r)' && ret=0 + _requested aliases expl 'module alias' \ + compadd "$suf[@]" -k 'modules[(R)alias*]' && ret=0 + done + return ret +fi Index: Src/cond.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/cond.c,v retrieving revision 1.10 diff -u -r1.10 cond.c --- Src/cond.c 28 May 2007 22:57:41 -0000 1.10 +++ Src/cond.c 29 May 2007 14:00:19 -0000 @@ -95,15 +95,12 @@ case COND_REGEX: { char *modname = isset(REMATCHPCRE) ? "zsh/pcre" : "zsh/regex"; - /* - * TODO: we just need to load the appropriate condition. - */ - if (load_module_silence(modname, NULL, 1) == 1) { + sprintf(overridename = overridebuf, "-%s-match", modname+4); + if (ensurefeature(modname, "c:", overridename+1)) { zwarnnam(fromtest, "%s not available for regex", modname); return 2; } - sprintf(overridename = overridebuf, "-%s-match", modname+4); ctype = COND_MODI; } /*FALLTHROUGH*/ Index: Src/exec.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/exec.c,v retrieving revision 1.114 diff -u -r1.114 exec.c --- Src/exec.c 28 May 2007 22:57:41 -0000 1.114 +++ Src/exec.c 29 May 2007 14:00:20 -0000 @@ -2012,7 +2012,12 @@ /* autoload the builtin if necessary */ if (!((Builtin) hn)->handlerfunc) { - (void)load_module(((Builtin) hn)->optstr, NULL); + /* + * Ensure the module is loaded and the + * feature corresponding to the builtin + * is enabled. + */ + (void)ensurefeature(((Builtin) hn)->optstr, "b:", hn->nam); hn = builtintab->getnode(builtintab, cmdarg); } assign = (hn && (hn->flags & BINF_MAGICEQUALS)); @@ -2229,7 +2234,7 @@ /* autoload the builtin if necessary */ if (!((Builtin) hn)->handlerfunc) { - (void)load_module(((Builtin) hn)->optstr, NULL); + (void)ensurefeature(((Builtin) hn)->optstr, "b:", cmdarg); hn = builtintab->getnode(builtintab, cmdarg); } break; Index: Src/module.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/module.c,v retrieving revision 1.26 diff -u -r1.26 module.c --- Src/module.c 28 May 2007 22:57:41 -0000 1.26 +++ Src/module.c 29 May 2007 14:00:20 -0000 @@ -389,7 +389,7 @@ /* This is a definition for an autoloaded condition, load the * * module if we haven't tried that already. */ if (f) { - (void)load_module_silence(p->module, NULL, 0); + (void)ensurefeature(p->module, "c:", name); f = 0; p = NULL; } else { @@ -907,7 +907,7 @@ removemathfunc(q, p); - (void)load_module_silence(n, NULL, 0); + (void)ensurefeature(n, "f:", name); return getmathfunc(name, 0); } @@ -2850,7 +2850,7 @@ ret = 1; return ret; } - + /**/ mod_export int handlefeatures(char *nam, Features f, int **enables) @@ -2860,3 +2860,20 @@ *enables = getfeatureenables(nam, f); return 0; } + +/* + * Ensure module "modname" is providing feature with "prefix" + * and "feature" (e.g. "b:", "limit"). + */ + +/**/ +mod_export int +ensurefeature(char *modname, char *prefix, char *feature) +{ + char *f = dyncat(prefix, feature); + char *features[2]; + + features[0] = f; + features[1] = NULL; + return require_module(NULL, modname, features); +} Index: Src/params.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/params.c,v retrieving revision 1.128 diff -u -r1.128 params.c --- Src/params.c 28 May 2007 22:57:41 -0000 1.128 +++ Src/params.c 29 May 2007 14:00:21 -0000 @@ -419,7 +419,7 @@ if (pm && pm->u.str && (pm->node.flags & PM_AUTOLOAD)) { char *mn = dupstring(pm->u.str); - if (load_module(mn, NULL) == 1) + if (ensurefeature(mn, "p:", nam)) return NULL; hn = gethashnode2(ht, nam); if (((Param) hn) == pm && (pm->node.flags & PM_AUTOLOAD)) { -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070 To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php To get further information regarding CSR, please visit our Investor Relations page at http://ir.csr.com/csr/about/overview