about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--Doc/Zsh/zle.yo20
-rw-r--r--Src/Zle/zle_main.c12
-rw-r--r--Src/Zle/zle_thingy.c11
4 files changed, 48 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index a368ff63d..86c3dbbf4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2003-12-12  Peter Stephenson  <pws@pwstephenson.fsnet.co.uk>
+
+	* 19281: Src/Zle/zle_main.c, Src/Zle/zle_thingy.c, Doc/Zsh/zle.yo:
+	zle-line-init, if defined as a widget, is called when zle
+	starts to read a line.
+
 2003-12-05  Oliver Kiddle  <opk@zsh.org>
 
 	* 19276: Completion/Base/Completer/_prefix: fix fallback used to
diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo
index 085424ff0..08a8d8f69 100644
--- a/Doc/Zsh/zle.yo
+++ b/Doc/Zsh/zle.yo
@@ -695,6 +695,26 @@ item(tt(WIDGET) (scalar))(
 The name of the widget currently being executed; read-only.
 )
 enditem()
+
+subsect(Special Widget)
+
+There is one user-defined widget which is special to the shell.
+If it does not exist, no special action is taken.  The environment
+provided is identical to that for any other editing widget.
+
+startitem()
+tindex(zle-line-init)
+item(tt(zle-line-init))(
+Executed every time the line editor is started to read a new line
+of input.  The following example puts the line editor into vi command
+mode when it starts up.
+
+example(zle-line-init() { zle -K vicmd; }
+zle -N zle-line-init)
+
+)
+enditem()
+
 sect(Standard Widgets)
 cindex(widgets, standard)
 The following is a list of all the standard widgets,
diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index 15423d231..c3317175c 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -348,7 +348,8 @@ raw_getkey(int keytmout, char *cptr)
 {
     long exp100ths;
     int ret;
-#ifdef HAS_TIO
+#if defined(HAS_TIO) && \
+  (defined(sun) || (!defined(HAVE_POLL) && !defined(HAVE_SELECT)))
     struct ttyinfo ti;
 #endif
 #ifndef HAVE_POLL
@@ -739,6 +740,7 @@ zleread(char *lp, char *rp, int flags)
     unsigned char *s;
     int old_errno = errno;
     int tmout = getiparam("TMOUT");
+    Thingy initthingy;
 
 #if defined(HAVE_POLL) || defined(HAVE_SELECT)
     baud = getiparam("BAUD");
@@ -821,6 +823,14 @@ zleread(char *lp, char *rp, int flags)
     initmodifier(&zmod);
     prefixflag = 0;
 
+    if ((initthingy = rthingy_nocreate("zle-line-init"))) {
+	char *args[2];
+	args[0] = initthingy->nam;
+	args[1] = NULL;
+	execzlefunc(initthingy, args);
+	unrefthingy(initthingy);
+    }
+
     zlecore();
 
     statusline = NULL;
diff --git a/Src/Zle/zle_thingy.c b/Src/Zle/zle_thingy.c
index 71eab02e7..91ee2c010 100644
--- a/Src/Zle/zle_thingy.c
+++ b/Src/Zle/zle_thingy.c
@@ -164,6 +164,17 @@ rthingy(char *nam)
     return refthingy(t);
 }
 
+/**/
+Thingy
+rthingy_nocreate(char *nam)
+{
+    Thingy t = (Thingy) thingytab->getnode2(thingytab, nam);
+
+    if(!t)
+	return NULL;
+    return refthingy(t);
+}
+
 /***********/
 /* widgets */
 /***********/