about summary refs log tree commit diff
path: root/Src/Zle
diff options
context:
space:
mode:
Diffstat (limited to 'Src/Zle')
-rw-r--r--Src/Zle/zle_keymap.c15
-rw-r--r--Src/Zle/zle_main.c24
-rw-r--r--Src/Zle/zle_utils.c32
3 files changed, 37 insertions, 34 deletions
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;
+}