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

PATCH: pass name ($0) and zmult ($1) to user-defined widgets



User-defined widgets should be able to change their behavior or repeat
their action when given a digit-argument.  They also ought to have a
usable $0 when FUNCTION_ARGZERO is set; I chose to pass the widget name,
so if you bind the same function to different widgets you can test for
$0 to tweak the behavior.

Index: Doc/Zsh/zle.yo
===================================================================
--- zle.yo	1998/06/01 17:08:43	1.1.1.1
+++ zle.yo	1998/06/12 08:33:25
@@ -102,6 +102,9 @@
 User-defined widgets, being implemented as shell functions,
 can execute any normal shell command.  They can also run other widgets
 (whether built-in or user-defined) using the tt(zle) builtin command.
+When tt(FUNCTION_ARGZERO) is set, they are passed their widget name
+(not their function name) as tt($0), and if tt(digit-argument) was
+used to enter a number prefix, that prefix is passed as tt($1).
 Finally, they can examine and edit the ZLE buffer being edited by
 reading and setting the special parameters described below.
 
Index: Src/Zle/zle_main.c
===================================================================
--- zle_main.c	1998/06/01 17:08:46	1.1.1.1
+++ zle_main.c	1998/06/12 08:25:14
@@ -591,10 +591,23 @@
 	    zsfree(msg);
 	    feep();
 	} else {
+	  char *name = 0, num[16];
+	  LinkList args;
 	  startparamscope();
 	  makezleparams();
-	  doshfunc(l, NULL, 0, 1);
+	  PERMALLOC {
+	    name = ztrdup(func->nam);
+	    args = newlinklist();
+	    addlinknode(args, name);
+	    if (zmod.flags & MOD_MULT) {
+	      sprintf(num, "%d", zmult);
+	      addlinknode(args, num);
+	    }
+	  } LASTALLOC;
+	  doshfunc(l, args, 0, 1);
 	  endparamscope();
+	  freelinklist(args, (FreeFunc) NULL);
+	  zsfree(name);
 	  lastcmd = 0;
 	}
     }

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



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