From a18f0202824ccd29a931edd2abc6d2caee23296c Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 1 Jul 2002 09:54:47 +0000 Subject: 17384: new recursive-edit widget. --- Src/Zle/iwidgets.list | 1 + Src/Zle/zle_main.c | 152 ++++++++++++++++++++++++++++---------------------- 2 files changed, 87 insertions(+), 66 deletions(-) (limited to 'Src') diff --git a/Src/Zle/iwidgets.list b/Src/Zle/iwidgets.list index da5bcc531..fbd45dacc 100644 --- a/Src/Zle/iwidgets.list +++ b/Src/Zle/iwidgets.list @@ -85,6 +85,7 @@ "quoted-insert", quotedinsert, ZLE_MENUCMP | ZLE_KEEPSUFFIX "quote-line", quoteline, 0 "quote-region", quoteregion, 0 +"recursive-edit", recursiveedit, ZLE_MENUCMP | ZLE_KEEPSUFFIX | ZLE_LASTCOL "redisplay", redisplay, ZLE_MENUCMP | ZLE_KEEPSUFFIX | ZLE_LASTCOL "redo", redo, ZLE_KEEPSUFFIX "reverse-menu-complete", reversemenucomplete, ZLE_MENUCMP | ZLE_KEEPSUFFIX | ZLE_ISCOMP diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c index 782bd472c..9332b509d 100644 --- a/Src/Zle/zle_main.c +++ b/Src/Zle/zle_main.c @@ -89,10 +89,11 @@ mod_export int eofchar; static int eofsent; static long keytimeout; -#ifdef HAVE_SELECT +#if defined(HAVE_SELECT) || defined(HAVE_POLL) /* Terminal baud rate */ static int baud; +static long costmult; #endif /* flags associated with last command */ @@ -631,6 +632,74 @@ getkey(int keytmout) return ret; } +/**/ +void +zlecore(void) +{ +#if !defined(HAVE_POLL) && defined(HAVE_SELECT) + struct timeval tv; + fd_set foofd; + + FD_ZERO(&foofd); +#endif + + zrefresh(); + + while (!done && !errflag) { + + statusline = NULL; + vilinerange = 0; + reselectkeymap(); + selectlocalmap(NULL); + bindk = getkeycmd(); + if (!ll && isfirstln && unset(IGNOREEOF) && c == eofchar) { + eofsent = 1; + break; + } + if (bindk) { + if (execzlefunc(bindk, zlenoargs)) + handlefeep(zlenoargs); + handleprefixes(); + /* for vi mode, make sure the cursor isn't somewhere illegal */ + if (invicmdmode() && cs > findbol() && + (cs == ll || line[cs] == '\n')) + cs--; + if (undoing) + handleundo(); + } else { + errflag = 1; + break; + } +#ifdef HAVE_POLL + if (baud && !(lastcmd & ZLE_MENUCMP)) { + struct pollfd pfd; + int to = cost * costmult / 1000; /* milliseconds */ + + if (to > 500) + to = 500; + pfd.fd = SHTTY; + pfd.events = POLLIN; + if (!kungetct && poll(&pfd, 1, to) <= 0) + zrefresh(); + } else +#else +# ifdef HAVE_SELECT + if (baud && !(lastcmd & ZLE_MENUCMP)) { + FD_SET(SHTTY, &foofd); + tv.tv_sec = 0; + if ((tv.tv_usec = cost * costmult) > 500000) + tv.tv_usec = 500000; + if (!kungetct && select(SHTTY+1, (SELECT_ARG_2_T) & foofd, + NULL, NULL, &tv) <= 0) + zrefresh(); + } else +# endif +#endif + if (!kungetct) + zrefresh(); + } +} + /* Read a line. It is returned metafied. */ /**/ @@ -641,14 +710,7 @@ zleread(char *lp, char *rp, int flags) int old_errno = errno; int tmout = getiparam("TMOUT"); -#if defined(HAVE_SELECT) || defined(HAVE_POLL) - long costmult; -# ifdef HAVE_POLL -# else - struct timeval tv; - fd_set foofd; -# endif - +#if defined(HAVE_POLL) || defined(HAVE_SELECT) baud = getiparam("BAUD"); costmult = (baud) ? 3840000L / baud : 0; #endif @@ -693,11 +755,6 @@ zleread(char *lp, char *rp, int flags) zlereadflags = flags; histline = curhist; -#ifndef HAVE_POLL -# ifdef HAVE_SELECT - FD_ZERO(&foofd); -# endif -#endif undoing = 1; line = (unsigned char *)zalloc((linesz = 256) + 2); virangeflag = lastcmd = done = cs = ll = mark = 0; @@ -732,60 +789,9 @@ zleread(char *lp, char *rp, int flags) lastcol = -1; initmodifier(&zmod); prefixflag = 0; - zrefresh(); - while (!done && !errflag) { - statusline = NULL; - vilinerange = 0; - reselectkeymap(); - selectlocalmap(NULL); - bindk = getkeycmd(); - if (!ll && isfirstln && unset(IGNOREEOF) && c == eofchar) { - eofsent = 1; - break; - } - if (bindk) { - if (execzlefunc(bindk, zlenoargs)) - handlefeep(zlenoargs); - handleprefixes(); - /* for vi mode, make sure the cursor isn't somewhere illegal */ - if (invicmdmode() && cs > findbol() && - (cs == ll || line[cs] == '\n')) - cs--; - if (undoing) - handleundo(); - } else { - errflag = 1; - break; - } -#ifdef HAVE_POLL - if (baud && !(lastcmd & ZLE_MENUCMP)) { - struct pollfd pfd; - int to = cost * costmult / 1000; /* milliseconds */ + zlecore(); - if (to > 500) - to = 500; - pfd.fd = SHTTY; - pfd.events = POLLIN; - if (!kungetct && poll(&pfd, 1, to) <= 0) - zrefresh(); - } else -#else -# ifdef HAVE_SELECT - if (baud && !(lastcmd & ZLE_MENUCMP)) { - FD_SET(SHTTY, &foofd); - tv.tv_sec = 0; - if ((tv.tv_usec = cost * costmult) > 500000) - tv.tv_usec = 500000; - if (!kungetct && select(SHTTY+1, (SELECT_ARG_2_T) & foofd, - NULL, NULL, &tv) <= 0) - zrefresh(); - } else -# endif -#endif - if (!kungetct) - zrefresh(); - } statusline = NULL; invalidatelist(); trashzle(); @@ -1233,6 +1239,20 @@ whereis(char **args) return 0; } +/**/ +int +recursiveedit(char **args) +{ + int locerror; + + zlecore(); + + locerror = errflag; + errflag = done = 0; + + return locerror; +} + /**/ mod_export void trashzle(void) -- cgit 1.4.1