summaryrefslogtreecommitdiff
path: root/Src/Zle/zle_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'Src/Zle/zle_main.c')
-rw-r--r--Src/Zle/zle_main.c72
1 files changed, 19 insertions, 53 deletions
diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index 442c31995..cec44c0ed 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -187,10 +187,6 @@ mod_export char *zlenoargs[1] = { NULL };
static char **raw_lp, **raw_rp;
-#ifdef FIONREAD
-static int delayzsetterm;
-#endif
-
/*
* File descriptors we are watching as well as the terminal fd.
* These are all for reading; we don't watch for writes or exceptions.
@@ -210,9 +206,6 @@ mod_export void
zsetterm(void)
{
struct ttyinfo ti;
-#if defined(FIONREAD)
- int val;
-#endif
if (fetchttyinfo) {
/*
@@ -224,30 +217,6 @@ zsetterm(void)
fetchttyinfo = 0;
}
-#if defined(FIONREAD)
- ioctl(SHTTY, FIONREAD, (char *)&val);
- if (val) {
- /*
- * Problems can occur on some systems when switching from
- * canonical to non-canonical input. The former is usually
- * set while running programmes, but the latter is necessary
- * for zle. If there is input in canonical mode, then we
- * need to read it without setting up the terminal. Furthermore,
- * while that input gets processed there may be more input
- * being typed (i.e. further typeahead). This means that
- * we can't set up the terminal for zle *at all* until
- * we are sure there is no more typeahead to come. So
- * if there is typeahead, we set the flag delayzsetterm.
- * Then getbyte() performs another FIONREAD call; if that is
- * 0, we have finally used up all the typeahead, and it is
- * safe to alter the terminal, which we do at that point.
- */
- delayzsetterm = 1;
- return;
- } else
- delayzsetterm = 0;
-#endif
-
/* sanitize the tty */
#ifdef HAS_TIO
shttyinfo.tio.c_lflag |= ICANON | ECHO;
@@ -343,7 +312,7 @@ zsetterm(void)
ti.ltchars.t_dsuspc = ti.ltchars.t_lnextc = -1;
#endif
-#if defined(TTY_NEEDS_DRAINING) && defined(TIOCOUTQ) && defined(HAVE_SELECT)
+#if defined(TIOCOUTQ) && defined(HAVE_SELECT)
if (baud) { /**/
int n = 0;
@@ -541,11 +510,7 @@ raw_getbyte(long do_keytmout, char *cptr)
* timeouts may be external, so we may have both a permanent watched
* fd and a long-term timeout.
*/
- if ((nwatch || tmout.tp != ZTM_NONE)
-#ifdef FIONREAD
- && ! delayzsetterm
-#endif
- ) {
+ if ((nwatch || tmout.tp != ZTM_NONE)) {
#if defined(HAVE_SELECT) || defined(HAVE_POLL)
int i, errtry = 0, selret;
# ifdef HAVE_POLL
@@ -779,7 +744,7 @@ raw_getbyte(long do_keytmout, char *cptr)
}
if (errflag) {
/* No sensible way of handling errors here */
- errflag = 0;
+ errflag &= ~ERRFLAG_ERROR;
/*
* Paranoia: don't run the hooks again this
* time.
@@ -883,14 +848,6 @@ getbyte(long do_keytmout, int *timeout)
if (kungetct)
ret = STOUC(kungetbuf[--kungetct]);
else {
-#ifdef FIONREAD
- if (delayzsetterm) {
- int val;
- ioctl(SHTTY, FIONREAD, (char *)&val);
- if (!val)
- zsetterm();
- }
-#endif
for (;;) {
int q = queue_signal_level();
dont_queue_signals();
@@ -925,7 +882,7 @@ getbyte(long do_keytmout, int *timeout)
die = 0;
if (!errflag && !retflag && !breaks && !exit_pending)
continue;
- errflag = 0;
+ errflag &= ~ERRFLAG_ERROR;
breaks = obreaks;
errno = old_errno;
return lastchar = EOF;
@@ -1067,6 +1024,7 @@ getrestchar(int inchar)
void
zlecore(void)
{
+ Keymap km;
#if !defined(HAVE_POLL) && defined(HAVE_SELECT)
struct timeval tv;
fd_set foofd;
@@ -1088,8 +1046,10 @@ zlecore(void)
statusline = NULL;
vilinerange = 0;
reselectkeymap();
- selectlocalmap(NULL);
+ selectlocalmap(invicmdmode() && region_active && (km = openkeymap("visual"))
+ ? km : NULL);
bindk = getkeycmd();
+ selectlocalmap(NULL);
if (bindk) {
if (!zlell && isfirstln && !(zlereadflags & ZLRF_IGNOREEOF) &&
lastchar == eofchar) {
@@ -1115,7 +1075,7 @@ zlecore(void)
DECCS();
handleundo();
} else {
- errflag = 1;
+ errflag |= ERRFLAG_ERROR;
break;
}
#ifdef HAVE_POLL
@@ -1273,6 +1233,10 @@ zleread(char **lp, char **rp, int flags, int context, char *init, char *finish)
zleactive = 1;
resetneeded = 1;
+ /*
+ * Start of the main zle read.
+ * Fully reset error conditions, including user interrupt.
+ */
errflag = retflag = 0;
lastcol = -1;
initmodifier(&zmod);
@@ -1289,7 +1253,9 @@ zleread(char **lp, char **rp, int flags, int context, char *init, char *finish)
zlecore();
if (errflag)
- setsparam("ZLE_LINE_ABORTED", zlegetline(NULL, NULL));
+ setsparam((zlecontext == ZLCON_VARED) ?
+ "ZLE_VARED_ABORTED" :
+ "ZLE_LINE_ABORTED", zlegetline(NULL, NULL));
if (done && !exit_pending && !errflag)
zlecallhook(finish, NULL);
@@ -1698,7 +1664,7 @@ bin_vared(char *name, char **args, Options ops, UNUSED(int func))
}
if (!t || errflag) {
/* error in editing */
- errflag = 0;
+ errflag &= ~ERRFLAG_ERROR;
breaks = obreaks;
if (t)
zsfree(t);
@@ -1818,7 +1784,7 @@ recursiveedit(UNUSED(char **args))
zrefresh();
zlecore();
- locerror = errflag;
+ locerror = errflag ? 1 : 0;
errflag = done = eofsent = 0;
return locerror;
@@ -2128,7 +2094,7 @@ finish_(UNUSED(Module m))
free(kring[i].buf);
zfree(kring, kringsize * sizeof(struct cutbuffer));
}
- for(i = 35; i--; )
+ for(i = 36; i--; )
zfree(vibuf[i].buf, vibuf[i].len);
/* editor entry points */