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

Re: Add a hook on isearch



On Sat, 18 Sep 2010 13:00:49 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Sep 18,  6:50pm, Mikael Magnusson wrote:
> Maybe it's time for a callhookzle() to go with callhookfunc() and
> runhookdef()?

This made me notice the arguments for zle-keymap-select were wrong: for a
user-defined widget, the arguments directly turn into function arguments,
so argument 0 is always the function name and any additional argument needs
to be the next argument (see doshfunc()).

Index: Src/Zle/zle_keymap.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_keymap.c,v
retrieving revision 1.35
diff -p -u -r1.35 zle_keymap.c
--- Src/Zle/zle_keymap.c	8 Sep 2010 12:32:32 -0000	1.35
+++ Src/Zle/zle_keymap.c	20 Sep 2010 09:00:46 -0000
@@ -486,22 +486,11 @@ selectkeymap(char *name, int fb)
     }
     if(name != curkeymapname) {
 	char *oname = curkeymapname;
-	Thingy chgthingy;
 
 	curkeymapname = ztrdup(name);
 
-	if (oname && zleactive && strcmp(oname, curkeymapname) &&
-	    (chgthingy = rthingy_nocreate("zle-keymap-select"))) {
-	    char *args[2];
-	    int saverrflag = errflag, savretflag = retflag;
-	    args[0] = oname;
-	    args[1] = NULL;
-	    errflag = retflag = 0;
-	    execzlefunc(chgthingy, args, 1);
-	    unrefthingy(chgthingy);
-	    errflag = saverrflag;
-	    retflag = savretflag;
-	}
+	if (oname && zleactive && strcmp(oname, curkeymapname))
+	    zlecallhook("zle-keymap-select", oname);
 	zsfree(oname);
     }
     curkeymap = km;
Index: Src/Zle/zle_main.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_main.c,v
retrieving revision 1.125
diff -p -u -r1.125 zle_main.c
--- Src/Zle/zle_main.c	8 Sep 2010 12:32:32 -0000	1.125
+++ Src/Zle/zle_main.c	20 Sep 2010 09:00:46 -0000
@@ -1115,7 +1115,6 @@ zleread(char **lp, char **rp, int flags,
     char *s;
     int old_errno = errno;
     int tmout = getiparam("TMOUT");
-    Thingy initthingy;
 
 #if defined(HAVE_POLL) || defined(HAVE_SELECT)
     /* may not be set, but that's OK since getiparam() returns 0 == off */
@@ -1215,32 +1214,15 @@ zleread(char **lp, char **rp, int flags,
 
     zrefresh();
 
-    if ((initthingy = rthingy_nocreate("zle-line-init"))) {
-	char *args[2];
-	args[0] = initthingy->nam;
-	args[1] = NULL;
-	execzlefunc(initthingy, args, 1);
-	unrefthingy(initthingy);
-	errflag = retflag = 0;
-    }
+    zlecallhook("zle-line-init", NULL);
 
     zlecore();
 
     if (errflag)
 	setsparam("ZLE_LINE_ABORTED", zlegetline(NULL, NULL));
 
-    if (done && !exit_pending && !errflag &&
-	(initthingy = rthingy_nocreate("zle-line-finish"))) {
-	int saverrflag = errflag;
-	int savretflag = retflag;
-	char *args[2];
-	args[0] = initthingy->nam;
-	args[1] = NULL;
-	execzlefunc(initthingy, args, 1);
-	unrefthingy(initthingy);
-	errflag = saverrflag;
-	retflag = savretflag;
-    }
+    if (done && !exit_pending && !errflag)
+	zlecallhook("zle-line-finish", NULL);
 
     statusline = NULL;
     invalidatelist();
Index: Src/Zle/zle_utils.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_utils.c,v
retrieving revision 1.56
diff -p -u -r1.56 zle_utils.c
--- Src/Zle/zle_utils.c	22 Mar 2010 19:49:07 -0000	1.56
+++ Src/Zle/zle_utils.c	20 Sep 2010 09:00:46 -0000
@@ -1237,3 +1237,35 @@ viundochange(char **args)
     } else
 	return undo(args);
 }
+
+/*
+ * Call a ZLE hook: a user-defined widget called at a specific point
+ * within the line editor.
+ *
+ * A single argument arg is passed to the function (in addition to the
+ * function name).  It may be NULL.
+ */
+
+/**/
+void
+zlecallhook(char *name, char *arg)
+{
+    Thingy thingy = rthingy_nocreate(name);
+    int saverrflag, savretflag;
+    char *args[3];
+
+    if (!thingy)
+	return;
+
+    saverrflag = errflag;
+    savretflag = retflag;
+
+    args[0] = thingy->nam;
+    args[1] = arg;
+    args[2] = NULL;
+    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