summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--Doc/Zsh/zle.yo9
-rw-r--r--Src/Zle/zle_thingy.c29
3 files changed, 35 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 803eeace0..8ba3c08c1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2004-09-02  Peter Stephenson  <pws@csr.com>
 
+	* 20303: Src/Zle/zle_thingy.c, Doc/Zsh/zle.yo: Make test for
+	zle -I more consistent with other uses of zle. Make zle widgets
+	runnable inside traps.
+
 	* 20300: Src/Zle/zle_main.c: typing ^D to list completions,
 	then two ^C's caused a spurious EOF.
 
diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo
index fe6ef04a6..7b59d32d3 100644
--- a/Doc/Zsh/zle.yo
+++ b/Doc/Zsh/zle.yo
@@ -505,9 +505,12 @@ to minimise disruption.
 Note that there are normally better ways of manipulating the display from
 within zle widgets; see, for example, `tt(zle -R)' above.
 
-The status is zero if zle is active and the current zle display has
-been invalidated (even if this was by a previous call to `tt(zle -I)'),
-else one.
+The returned status is zero if a zle widget can be called immediately.
+Note this is independent of whether the display has been invalidated.
+For example, if a completion widget is active a zle widget cannot be used
+and the status is one even if the display was invalidated; on the other
+hand, the status may be zero if the display was invalidated by a previous
+call to `tt(zle -I)'.
 )
 item(var(widget) tt([ -n) var(num) tt(]) tt([ -N ]) var(args) ...)(
 Invoke the specified widget.  This can only be done when ZLE is
diff --git a/Src/Zle/zle_thingy.c b/Src/Zle/zle_thingy.c
index 53eb927f9..c252eee1e 100644
--- a/Src/Zle/zle_thingy.c
+++ b/Src/Zle/zle_thingy.c
@@ -619,6 +619,23 @@ bin_zle_complete(char *name, char **args, UNUSED(Options ops), UNUSED(char func)
 
 /**/
 static int
+zle_usable()
+{
+    return zleactive && !incompctlfunc && !incompfunc
+#if 0
+	/*
+	 * PWS experiment: commenting this out allows zle widgets
+	 * in signals, hooks etc.  I'm not sure if this has a down side;
+	 * it ought to be that zleactive is good enough to test whether
+	 * widgets are callable.
+	 */
+	&& sfcontext == SFC_WIDGET
+#endif
+	   ;
+}
+
+/**/
+static int
 bin_zle_call(char *name, char **args, UNUSED(Options ops), UNUSED(char func))
 {
     Thingy t;
@@ -629,10 +646,9 @@ bin_zle_call(char *name, char **args, UNUSED(Options ops), UNUSED(char func))
     if (!wname) {
 	if (saveflag)
 	    zmod = modsave;
-	return (!zleactive || incompctlfunc || incompfunc ||
-		sfcontext != SFC_WIDGET);
+	return !zle_usable();
     }
-    if(!zleactive || incompctlfunc || incompfunc || sfcontext != SFC_WIDGET) {
+    if(!zle_usable()) {
 	zwarnnam(name, "widgets can only be called when ZLE is active",
 	    NULL, 0);
 	return 1;
@@ -685,10 +701,15 @@ bin_zle_call(char *name, char **args, UNUSED(Options ops), UNUSED(char func))
 static int
 bin_zle_invalidate(UNUSED(char *name), UNUSED(char **args), UNUSED(Options ops), UNUSED(char func))
 {
+    /*
+     * Trash zle if trashable, but only indicate that zle is usable
+     * if it's possible to call a zle widget next.  This is not
+     * true if a completion widget is active.
+     */
     if (zleactive) {
 	if (!trashedzle)
 	    trashzle();
-	return 0;
+	return !zle_usable();
     } else
 	return 1;
 }