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

Re: accept-line-and-down-history and push-input



On Tue, 26 Oct 2010 07:55:44 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> (I'm beginning to think that zle-line-init should be a builtin widget
> that calls an array of hook functions, ala precmd.)

I've been thinking along those lines, except that the array of hook
functions would be the alternative to the widget, as with chpwd and
friends, i.e. you could still define zle-line-init if you wanted a
simple life but zle_line_init_functions could contain an additional set
of widgets.  Something like the following.

  zle_line_init_functions=(zle-le-test)
  zle-le-test() { zle -M Initialised.; }
  zle -N zle-le-test

Not sure how to keep the name of the array entirely within zle, but I'm
not sure it's necessary: using variables with a prefix zle_ is natural
enough.

Index: Src/Zle/zle_utils.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_utils.c,v
retrieving revision 1.57
diff -p -u -r1.57 zle_utils.c
--- Src/Zle/zle_utils.c	20 Sep 2010 09:27:46 -0000	1.57
+++ Src/Zle/zle_utils.c	26 Oct 2010 15:16:42 -0000
@@ -1250,21 +1250,48 @@ viundochange(char **args)
 void
 zlecallhook(char *name, char *arg)
 {
-    Thingy thingy = rthingy_nocreate(name);
+    Thingy thingy;
     int saverrflag, savretflag;
-    char *args[3];
+    char *args[3], *arrname, **funcarray, *ptr;
+    const char suffix[] = "_functions";
 
-    if (!thingy)
-	return;
+    /* Get the name of the corresponding hook array */
+    arrname = zalloc(strlen(name) + strlen(suffix) + 1);
+    sprintf(arrname, "%s%s", name, suffix);
+    for (ptr = arrname; *ptr; ptr++) {
+	if (*ptr == '-')
+	    *ptr = '_';
+    }
 
     saverrflag = errflag;
     savretflag = retflag;
 
-    args[0] = thingy->nam;
     args[1] = arg;
     args[2] = NULL;
-    execzlefunc(thingy, args, 1);
-    unrefthingy(thingy);
+
+    thingy = rthingy_nocreate(name);
+    if (thingy) {
+	args[0] = thingy->nam;
+	execzlefunc(thingy, args, 1);
+	unrefthingy(thingy);
+    }
+
+    funcarray = getaparam(arrname);
+    if (funcarray) {
+	/* in case the array changes during use */
+	funcarray = arrdup(funcarray);
+	for (; *funcarray; funcarray++) {
+	    errflag = 0;
+	    retflag = 0;
+
+	    thingy = rthingy_nocreate(*funcarray);
+	    if (thingy) {
+		args[0] = thingy->nam;
+		execzlefunc(thingy, args, 1);
+		unrefthingy(thingy);
+	    }
+	}
+    }
 
     errflag = saverrflag;
     retflag = savretflag;


-- 
Peter Stephenson <pws@xxxxxxx>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK



Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom



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