zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: pass name ($0) and zmult ($1) to user-defined widgets
@ 1998-06-12  8:38 Bart Schaefer
  1998-06-12  9:37 ` Zefram
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 1998-06-12  8:38 UTC (permalink / raw)
  To: zsh-workers

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1998-06-12 16:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-06-12  8:38 PATCH: pass name ($0) and zmult ($1) to user-defined widgets Bart Schaefer
1998-06-12  9:37 ` Zefram
1998-06-12 15:54   ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).