zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh workers <zsh-workers@zsh.org>
Subject: [PATCH] Widget fallbacks (Re: Bad effect of error in zle-line-pre-redraw)
Date: Sun, 13 Nov 2016 11:16:03 -0800	[thread overview]
Message-ID: <161113111603.ZM19084@torch.brasslantern.com> (raw)
In-Reply-To: <161112124105.ZM4155@torch.brasslantern.com>

On Nov 12, 12:41pm, Bart Schaefer wrote:
}
} On Nov 12,  6:54pm, Mikael Magnusson wrote:
} }
} } There are many many more ways to break a shell session, surely.
} 
} Of course; e.g. just doing
} 
} zle -N self-insert this-does-not-exist

Seems to me that if we have immortal widgets backing the built-ins,
we should use them in cases like this?

IMO the only controversial bit of this patch is the final hunk.  As
there is no way to tell at what point the user-defined widget failed,
calling the immortal counterpart might duplicate something that was
already done.  In the other cases we know nothing else has happened.

An alternate approach for that final bit is to simply bail out of ZLE
entirely (opts[USEZLE] = 0).  That's a little tricky if we're a couple
of user-defined widgets down the call stack, as localoptions may end
up clobbering whatever we do here.


diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index 96b631e..1652b7c 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;


      parent reply	other threads:[~2016-11-13 20:08 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-12 17:03 Bad effect of error in zle-line-pre-redraw Bart Schaefer
2016-11-12 17:54 ` Mikael Magnusson
2016-11-12 20:41   ` Bart Schaefer
2016-11-13 14:45     ` Mikael Magnusson
2016-11-13 18:55       ` Bart Schaefer
2016-11-14 11:15         ` Mikael Magnusson
2016-11-13 19:16     ` Bart Schaefer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=161113111603.ZM19084@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).