about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBarton E. Schaefer <schaefer@zsh.org>2016-11-13 15:52:09 -0800
committerBarton E. Schaefer <schaefer@zsh.org>2016-11-13 15:52:09 -0800
commitcbb9ca3dfbb6ecaa8b5099a3302b196a91a026d8 (patch)
tree5d60a4d5dc315c2dfcb9b2de02d3e82bd3722a78
parent7b8f63871372e0cd01e9ed9bf313a8a96d9a1965 (diff)
downloadzsh-cbb9ca3dfbb6ecaa8b5099a3302b196a91a026d8.tar.gz
zsh-cbb9ca3dfbb6ecaa8b5099a3302b196a91a026d8.tar.xz
zsh-cbb9ca3dfbb6ecaa8b5099a3302b196a91a026d8.zip
39934: if a widget execution fails, try to execute a corresponding immortal widget instead.
-rw-r--r--ChangeLog3
-rw-r--r--Src/Zle/zle_main.c18
2 files changed, 18 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 8345fb23f..586194454 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2016-11-13  Barton E. Schaefer  <schaefer@zsh.org>
 
+	* 39934: Src/Zle/zle_main.c: if a widget execution fails, try to
+	execute a corresponding immortal widget instead.
+
 	* 39933: Src/Zle/zle_main.c: more of zlecallhook() in redrawhook(),
 	add commentary on some of the differences
 
diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index 96b631eeb..1652b7cd4 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -1368,6 +1368,16 @@ zleread(char **lp, char **rp, int flags, int context, char *init, char *finish)
     return s;
 }
 
+/**/
+static int
+execimmortal(Thingy func, char **args)
+{
+    Thingy immortal = rthingy_nocreate(dyncat(".", func->nam));
+    if (immortal)
+	return execzlefunc(immortal, args, 0);
+    return 1;
+}
+
 /*
  * Execute a widget.  The third argument indicates that the global
  * variable bindk should be set temporarily so that WIDGET etc.
@@ -1389,7 +1399,7 @@ execzlefunc(Thingy func, char **args, int set_bindk)
 	remetafy = 1;
     }
 
-    if(func->flags & DISABLED) {
+    if (func->flags & DISABLED) {
 	/* this thingy is not the name of a widget */
 	char *nm = nicedup(func->nam, 0);
 	char *msg = tricat("No such widget `", nm, "'");
@@ -1397,7 +1407,7 @@ execzlefunc(Thingy func, char **args, int set_bindk)
 	zsfree(nm);
 	showmsg(msg);
 	zsfree(msg);
-	ret = 1;
+	ret = execimmortal(func, args);
     } else if((w = func->widget)->flags & (WIDGET_INT|WIDGET_NCOMP)) {
 	int wflags = w->flags;
 
@@ -1461,7 +1471,7 @@ execzlefunc(Thingy func, char **args, int set_bindk)
 	    zsfree(nm);
 	    showmsg(msg);
 	    zsfree(msg);
-	    ret = 1;
+	    ret = execimmortal(func, args);
 	} else {
 	    int osc = sfcontext, osi = movefd(0);
 	    int oxt = isset(XTRACE);
@@ -1483,6 +1493,8 @@ execzlefunc(Thingy func, char **args, int set_bindk)
 	    opts[XTRACE] = oxt;
 	    sfcontext = osc;
 	    endparamscope();
+	    if (errflag == ERRFLAG_ERROR && !(ret = execimmortal(func, args)))
+		errflag &= ~ERRFLAG_ERROR;
 	    lastcmd = w->flags & ~(WIDGET_INUSE|WIDGET_FREE);
 	    if (inuse) {
 		w->flags &= WIDGET_INUSE|WIDGET_FREE;