Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: autoload -X inside an anonymous function



On Wed, 19 Sep 2012 07:58:11 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> } I can't see any reason why it wouldn't work if you simply
> } added -m to the list of options accepted by autoload (or -X to
> } functions).
> 
> I misread the test at 2686 -- that one is using OPT_MINUS(), whereas
> the one at 2876 is OPT_ISSET().  So this is there specifically *to*
> implement "autoload -m +X", even though autoload doesn't currently
> allow -m in its args list.

Seems straightforward with an extra test.

I discovered while doing this that "autoload +X _path_files" didn't
work, it doesn't like the absence of the semicolon in the braces.  If
anyone wants to work out why, be me guest.

Index: Completion/Unix/Type/_path_files
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_path_files,v
retrieving revision 1.58
diff -p -u -r1.58 _path_files
--- Completion/Unix/Type/_path_files	5 Sep 2011 22:01:12 -0000	1.58
+++ Completion/Unix/Type/_path_files	20 Sep 2012 19:33:31 -0000
@@ -198,7 +198,7 @@ zstyle -T ":completion:${curcontext}:pat
   path_completion=1
 
 if [[ -n "$compstate[pattern_match]" ]]; then
-  if { [[ -z "$SUFFIX" ]] && _have_glob_qual "$PREFIX" complete } ||
+  if { [[ -z "$SUFFIX" ]] && _have_glob_qual "$PREFIX" complete; } ||
     _have_glob_qual "$SUFFIX" complete; then
     # Copy all glob qualifiers from the line to
     # the patterns used when generating matches
Index: Doc/Zsh/builtins.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/builtins.yo,v
retrieving revision 1.142
diff -p -u -r1.142 builtins.yo
--- Doc/Zsh/builtins.yo	21 Aug 2012 18:03:03 -0000	1.142
+++ Doc/Zsh/builtins.yo	20 Sep 2012 19:33:31 -0000
@@ -108,7 +108,7 @@ ifnzman(noderef(Aliasing)).
 findex(autoload)
 cindex(functions, autoloading)
 cindex(autoloading functions)
-item(tt(autoload) [ {tt(PLUS())|tt(-)}tt(UXktz) ] [ tt(-w) ] [ var(name) ... ])(
+item(tt(autoload) [ {tt(PLUS())|tt(-)}tt(UXkmtz) ] [ tt(-w) ] [ var(name) ... ])(
 Equivalent to tt(functions -u), with the exception of tt(-X)/tt(+X) and
 tt(-w).
 
@@ -129,6 +129,9 @@ undefined and marked for autoloading.  I
 enabled, the function created will contain the contents of the file
 plus a call to the function itself appended to it, thus giving normal
 ksh autoloading behaviour on the first call to the function.
+If the tt(-m) flag is also given each var(name) is treated as a
+pattern and all functions already marked for autoload that match the
+pattern are loaded.
 
 With the tt(-w) flag, the var(name)s are taken as names of files compiled
 with the tt(zcompile) builtin, and all functions defined in them are
Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.262
diff -p -u -r1.262 builtin.c
--- Src/builtin.c	8 Sep 2012 19:19:07 -0000	1.262
+++ Src/builtin.c	20 Sep 2012 19:33:31 -0000
@@ -46,7 +46,7 @@ static struct builtin builtins[] =
     BUILTIN(".", BINF_PSPECIAL, bin_dot, 1, -1, 0, NULL, NULL),
     BUILTIN(":", BINF_PSPECIAL, bin_true, 0, -1, 0, NULL, NULL),
     BUILTIN("alias", BINF_MAGICEQUALS | BINF_PLUSOPTS, bin_alias, 0, -1, 0, "Lgmrs", NULL),
-    BUILTIN("autoload", BINF_PLUSOPTS, bin_functions, 0, -1, 0, "ktTUwXz", "u"),
+    BUILTIN("autoload", BINF_PLUSOPTS, bin_functions, 0, -1, 0, "mktTUwXz", "u"),
     BUILTIN("bg", 0, bin_fg, 0, -1, BIN_BG, NULL, NULL),
     BUILTIN("break", BINF_PSPECIAL, bin_break, 0, 1, BIN_BREAK, NULL, NULL),
     BUILTIN("bye", 0, bin_break, 0, 1, BIN_EXIT, NULL, NULL),
@@ -2882,7 +2882,7 @@ bin_functions(char *name, char **argv, O
 	    if ((pprog = patcompile(*argv, PAT_STATIC, 0))) {
 		/* with no options, just print all functions matching the glob pattern */
 		queue_signals();
-		if (!(on|off)) {
+		if (!(on|off) && !OPT_ISSET(ops,'X')) {
 		    scanmatchtable(shfunctab, pprog, 1, 0, DISABLED,
 				   shfunctab->printnode, pflags);
 		} else {

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



Messages sorted by: Reverse Date, Date, Thread, Author