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

PATCH: widget called when zle starts.



If it's really this simple, it's definitely worth having.

Comment on the name, if you like.  The idea is that there could
conceivably be other zle-<something-else>-<init-or-exit-or-change>
special widgets in future.

An extra chunk simply shuts up a long-standing warning from gcc.

Index: Src/Zle/zle_main.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_main.c,v
retrieving revision 1.37
diff -u -r1.37 zle_main.c
--- Src/Zle/zle_main.c	3 Nov 2003 13:57:53 -0000	1.37
+++ Src/Zle/zle_main.c	12 Dec 2003 22:42:21 -0000
@@ -348,7 +348,8 @@
 {
     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 @@
     unsigned char *s;
     int old_errno = errno;
     int tmout = getiparam("TMOUT");
+    Thingy initthingy;
 
 #if defined(HAVE_POLL) || defined(HAVE_SELECT)
     baud = getiparam("BAUD");
@@ -820,6 +822,14 @@
     lastcol = -1;
     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();
 
Index: Src/Zle/zle_thingy.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_thingy.c,v
retrieving revision 1.11
diff -u -r1.11 zle_thingy.c
--- Src/Zle/zle_thingy.c	29 Oct 2003 19:17:48 -0000	1.11
+++ Src/Zle/zle_thingy.c	12 Dec 2003 22:42:22 -0000
@@ -164,6 +164,17 @@
     return refthingy(t);
 }
 
+/**/
+Thingy
+rthingy_nocreate(char *nam)
+{
+    Thingy t = (Thingy) thingytab->getnode2(thingytab, nam);
+
+    if(!t)
+	return NULL;
+    return refthingy(t);
+}
+
 /***********/
 /* widgets */
 /***********/
Index: Doc/Zsh/zle.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/zle.yo,v
retrieving revision 1.30
diff -u -r1.30 zle.yo
--- Doc/Zsh/zle.yo	22 May 2003 09:48:28 -0000	1.30
+++ Doc/Zsh/zle.yo	12 Dec 2003 22:42:28 -0000
@@ -695,6 +695,26 @@
 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,

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxx>
Work: pws@xxxxxxx
Web: http://www.pwstephenson.fsnet.co.uk



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