about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--Src/Zle/zle_keymap.c15
-rw-r--r--Src/Zle/zle_main.c24
-rw-r--r--Src/Zle/zle_utils.c32
4 files changed, 44 insertions, 35 deletions
diff --git a/ChangeLog b/ChangeLog
index 07185d28b..ab8e1ef3c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2010-09-20  Peter Stephenson  <pws@csr.com>
+
+	* 28282: Src/Zle/zle_keymap.c, Src/Zle/zle_main.c,
+	Src/zle_utils.c: new function zlecallhook() and fix argument to
+	zle-keymap-select.
+
 2010-09-19  Barton E. Schaefer  <schaefer@zsh.org>
 
 	* 28268: Src/builtin.c: I/O to a terminated (or never created)
@@ -13662,5 +13668,5 @@
 
 *****************************************************
 * This is used by the shell to define $ZSH_PATCHLEVEL
-* $Revision: 1.5084 $
+* $Revision: 1.5085 $
 *****************************************************
diff --git a/Src/Zle/zle_keymap.c b/Src/Zle/zle_keymap.c
index 0531c18ca..a08caa069 100644
--- a/Src/Zle/zle_keymap.c
+++ b/Src/Zle/zle_keymap.c
@@ -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;
diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index 641880ccf..f9e8b7387 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -1115,7 +1115,6 @@ zleread(char **lp, char **rp, int flags, int context)
     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, int context)
 
     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();
diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c
index cc84eb8bb..291bdd3cb 100644
--- a/Src/Zle/zle_utils.c
+++ b/Src/Zle/zle_utils.c
@@ -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;
+}