From ca3bc0d95d7deab4f5381f12b15047de748c0814 Mon Sep 17 00:00:00 2001 From: Jun-ichi Takimoto Date: Sat, 30 Jan 2016 00:25:53 +0900 Subject: 37838: use UNUSED() consistently --- Src/Zle/zle_utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Src/Zle/zle_utils.c') diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c index 6e9a98bde..a2c88102a 100644 --- a/Src/Zle/zle_utils.c +++ b/Src/Zle/zle_utils.c @@ -1678,7 +1678,7 @@ viundochange(char **args) /**/ int -splitundo(char **args) +splitundo(UNUSED(char **args)) { if (vistartchange >= 0) { mergeundo(); -- cgit v1.2.3 From a4020e10a33f3f78681a2e18fb7add56338d4e81 Mon Sep 17 00:00:00 2001 From: Jun-ichi Takimoto Date: Wed, 3 Feb 2016 01:24:56 +0900 Subject: 37868: add 'static' to file local variables --- ChangeLog | 8 ++++++++ Src/Modules/curses.c | 2 +- Src/Modules/param_private.c | 10 +++++----- Src/Modules/tcp.c | 2 +- Src/Modules/termcap.c | 2 +- Src/Modules/zftp.c | 8 ++++---- Src/Zle/complist.c | 2 +- Src/Zle/zle_misc.c | 2 +- Src/Zle/zle_utils.c | 4 ++-- Src/cond.c | 3 ++- Src/exec.c | 2 -- Src/glob.c | 2 +- Src/jobs.c | 6 +++--- Src/params.c | 2 +- Src/prompt.c | 2 +- Src/utils.c | 4 ++-- 16 files changed, 34 insertions(+), 27 deletions(-) (limited to 'Src/Zle/zle_utils.c') diff --git a/ChangeLog b/ChangeLog index d4adbe886..a8e76e238 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2016-02-03 Jun-ichi Takimoto + + * 37868: Src/Modules/curses.c, Src/Modules/param_private.c, + Src/Modules/tcp.c, Src/Modules/termcap.c, Src/Modules/zftp.c, + Src/Zle/complist.c, Src/Zle/zle_misc.c, Src/Zle/zle_utils.c, + Src/cond.c, Src/exec.c, Src/glob.c, Src/jobs.c, Src/params.c, + Src/prompt.c, Src/utils.c: add 'static' to file local variables. + 2016-01-31 Barton E. Schaefer * 37859: Src/text.c: NULL-terminate cond_binary_ops static array. diff --git a/Src/Modules/curses.c b/Src/Modules/curses.c index b8a79ed11..a04841a85 100644 --- a/Src/Modules/curses.c +++ b/Src/Modules/curses.c @@ -202,7 +202,7 @@ static const struct zcurses_mouse_event zcurses_mouse_map[] = { { 0, 0, 0 } }; -mmask_t zcurses_mouse_mask = ALL_MOUSE_EVENTS; +static mmask_t zcurses_mouse_mask = ALL_MOUSE_EVENTS; #endif diff --git a/Src/Modules/param_private.c b/Src/Modules/param_private.c index 2f51cb099..86416c5c5 100644 --- a/Src/Modules/param_private.c +++ b/Src/Modules/param_private.c @@ -42,19 +42,19 @@ struct gsu_closure { void *g; }; -const struct gsu_scalar scalar_private_gsu = +static const struct gsu_scalar scalar_private_gsu = { pps_getfn, pps_setfn, pps_unsetfn }; -const struct gsu_integer integer_private_gsu = +static const struct gsu_integer integer_private_gsu = { ppi_getfn, ppi_setfn, ppi_unsetfn }; -const struct gsu_float float_private_gsu = +static const struct gsu_float float_private_gsu = { ppf_getfn, ppf_setfn, ppf_unsetfn }; -const struct gsu_array array_private_gsu = +static const struct gsu_array array_private_gsu = { ppa_getfn, ppa_setfn, ppa_unsetfn }; -const struct gsu_hash hash_private_gsu = +static const struct gsu_hash hash_private_gsu = { pph_getfn, pph_setfn, pph_unsetfn }; /* diff --git a/Src/Modules/tcp.c b/Src/Modules/tcp.c index 5af68834f..dec12142b 100644 --- a/Src/Modules/tcp.c +++ b/Src/Modules/tcp.c @@ -208,7 +208,7 @@ freehostent(UNUSED(struct hostent *ptr)) /**/ #endif /* !HAVE_GETIPNODEBYNAME */ -LinkList ztcp_sessions; +static LinkList ztcp_sessions; /* "allocate" a tcp_session */ static Tcp_session diff --git a/Src/Modules/termcap.c b/Src/Modules/termcap.c index 29c28360c..60a6e138a 100644 --- a/Src/Modules/termcap.c +++ b/Src/Modules/termcap.c @@ -295,7 +295,7 @@ scantermcap(UNUSED(HashTable ht), ScanFunc func, int flags) } } -struct paramdef partab[] = { +static struct paramdef partab[] = { SPECIALPMDEF("termcap", PM_READONLY, NULL, gettermcap, scantermcap) }; diff --git a/Src/Modules/zftp.c b/Src/Modules/zftp.c index b4081df5f..deed35e2f 100644 --- a/Src/Modules/zftp.c +++ b/Src/Modules/zftp.c @@ -344,10 +344,10 @@ static int zfsesscnt; */ /* flags for alarm set, alarm gone off */ -int zfalarmed, zfdrrrring; +static int zfalarmed, zfdrrrring; /* remember old alarm status */ -time_t oaltime; -unsigned int oalremain; +static time_t oaltime; +static unsigned int oalremain; /* * Where to jump to when the alarm goes off. This is much @@ -357,7 +357,7 @@ unsigned int oalremain; * * gcc -O gives apparently spurious `may be clobbered by longjmp' warnings. */ -jmp_buf zfalrmbuf; +static jmp_buf zfalrmbuf; /* The signal handler itself */ diff --git a/Src/Zle/complist.c b/Src/Zle/complist.c index 0ccb88505..06a07a4e8 100644 --- a/Src/Zle/complist.c +++ b/Src/Zle/complist.c @@ -113,7 +113,7 @@ static Cmgroup *mgtab, *mgtabp; * Allow us to keep track of pointer arithmetic for mgtab; could * just as well have been for mtab but wasn't. */ -int mgtabsize; +static int mgtabsize; #endif /* diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c index 0483f758d..25f65b39c 100644 --- a/Src/Zle/zle_misc.c +++ b/Src/Zle/zle_misc.c @@ -1497,7 +1497,7 @@ struct suffixset { }; /* The list of suffix structures */ -struct suffixset *suffixlist; +static struct suffixset *suffixlist; /* Shell function to call to remove the suffix. */ diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c index a2c88102a..68794c66a 100644 --- a/Src/Zle/zle_utils.c +++ b/Src/Zle/zle_utils.c @@ -587,7 +587,7 @@ struct zle_position { }; /* LIFO stack of positions */ -struct zle_position *zle_positions; +static struct zle_position *zle_positions; /* * Save positions including cursor, end-of-line and @@ -1412,7 +1412,7 @@ zlong undo_changeno; /* If positive, don't undo beyond this point */ -zlong undo_limitno; +static zlong undo_limitno; /**/ void diff --git a/Src/cond.c b/Src/cond.c index c5ab65eea..0381fe94b 100644 --- a/Src/cond.c +++ b/Src/cond.c @@ -30,7 +30,8 @@ #include "zsh.mdh" #include "cond.pro" -int tracingcond; +/**/ +int tracingcond; /* updated by execcond() in exec.c */ static char *condstr[COND_MOD] = { "!", "&&", "||", "==", "!=", "<", ">", "-nt", "-ot", "-ef", "-eq", diff --git a/Src/exec.c b/Src/exec.c index 352615c83..b60fc90bd 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -4518,8 +4518,6 @@ spawnpipes(LinkList l, int nullexec) } } -extern int tracingcond; - /* evaluate a [[ ... ]] */ /**/ diff --git a/Src/glob.c b/Src/glob.c index 69de15544..2051016ec 100644 --- a/Src/glob.c +++ b/Src/glob.c @@ -306,7 +306,7 @@ statfullpath(const char *s, struct stat *st, int l) /* This may be set by qualifier functions to an array of strings to insert * into the list instead of the original string. */ -char **inserts; +static char **inserts; /* add a match to the list */ diff --git a/Src/jobs.c b/Src/jobs.c index b47ba8c60..2a9dbe7d6 100644 --- a/Src/jobs.c +++ b/Src/jobs.c @@ -1970,9 +1970,9 @@ struct bgstatus { }; typedef struct bgstatus *Bgstatus; /* The list of those entries */ -LinkList bgstatus_list; +static LinkList bgstatus_list; /* Count of entries. Reaches value of _SC_CHILD_MAX and stops. */ -long bgstatus_count; +static long bgstatus_count; /* * Remove and free a bgstatus entry. @@ -2372,7 +2372,7 @@ bin_fg(char *name, char **argv, Options ops, int func) return retval; } -const struct { +static const struct { const char *name; int num; } alt_sigs[] = { diff --git a/Src/params.c b/Src/params.c index a1f0292cc..76ed61c39 100644 --- a/Src/params.c +++ b/Src/params.c @@ -416,7 +416,7 @@ IPDEF10("pipestatus", pipestatus_gsu), * and $@, this is not readonly. This parameter is not directly * visible in user space. */ -initparam argvparam_pm = IPDEF9F("", &pparams, NULL, \ +static initparam argvparam_pm = IPDEF9F("", &pparams, NULL, \ PM_ARRAY|PM_SPECIAL|PM_DONTIMPORT); #undef BR diff --git a/Src/prompt.c b/Src/prompt.c index be067ee7e..831c4f948 100644 --- a/Src/prompt.c +++ b/Src/prompt.c @@ -1831,7 +1831,7 @@ struct colour_sequences { char *end; /* Escape sequence terminator */ char *def; /* Code to reset default colour */ }; -struct colour_sequences fg_bg_sequences[2]; +static struct colour_sequences fg_bg_sequences[2]; /* * We need a buffer for colour sequence composition. It may diff --git a/Src/utils.c b/Src/utils.c index 053731cfa..de4af5a51 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -56,12 +56,12 @@ typedef struct widechar_array *Widechar_array; * The wordchars variable turned into a wide character array. * This is much more convenient for testing. */ -struct widechar_array wordchars_wide; +static struct widechar_array wordchars_wide; /* * The same for the separators (IFS) array. */ -struct widechar_array ifs_wide; +static struct widechar_array ifs_wide; /* Function to set one of the above from the multibyte array */ -- cgit v1.2.3 From 3fdf1f16e34d22ebdb40bd411467f7b977ec8bb6 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Thu, 2 Jun 2016 12:48:10 +0200 Subject: 38540: fix undo problem by not moving the current change when only undoing a history line change --- ChangeLog | 5 +++++ Src/Zle/zle_utils.c | 11 ++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'Src/Zle/zle_utils.c') diff --git a/ChangeLog b/ChangeLog index 9f1220d49..59a2375d1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-06-02 Oliver Kiddle + + * 38540: Src/Zle/zle_utils.c: fix undo problem by not moving + the current change when only undoing a history line change + 2016-06-02 Peter Stephenson * users/21603: Src/utils.c: Don't do second attempt at read/poll diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c index 68794c66a..80219a441 100644 --- a/Src/Zle/zle_utils.c +++ b/Src/Zle/zle_utils.c @@ -1589,9 +1589,14 @@ undo(char **args) break; if (prev->changeno <= undo_limitno && !*args) return 1; - if (!unapplychange(prev) && last_change >= 0) - unapplychange(prev); - curchange = prev; + if (!unapplychange(prev)) { + if (last_change >= 0) { + unapplychange(prev); + curchange = prev; + } + } else { + curchange = prev; + } } while (last_change >= (zlong)0 || (curchange->flags & CH_PREV)); setlastline(); return 0; -- cgit v1.2.3 From 56e3d23b98628a50359e2a54bdb1837d063802df Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sun, 13 Nov 2016 18:15:23 -0800 Subject: unposted: comment in zlecallhook() points to redrawhook() just in case --- ChangeLog | 3 +++ Src/Zle/zle_utils.c | 2 ++ 2 files changed, 5 insertions(+) (limited to 'Src/Zle/zle_utils.c') diff --git a/ChangeLog b/ChangeLog index 586194454..3ca016ef4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2016-11-13 Barton E. Schaefer + * unposted: Src/Zle/zle_utils.c: comment in zlecallhook() points + to redrawhook() just in case + * 39934: Src/Zle/zle_main.c: if a widget execution fails, try to execute a corresponding immortal widget instead. diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c index 80219a441..4007c1112 100644 --- a/Src/Zle/zle_utils.c +++ b/Src/Zle/zle_utils.c @@ -1725,6 +1725,8 @@ zlecallhook(char *name, char *arg) if (!thingy) return; + /* If anything here needs changing, see also redrawhook() */ + saverrflag = errflag; savretflag = retflag; -- cgit v1.2.3 From cb5f100bd38a3b21739897fb4236db0700b39477 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Sun, 20 Nov 2016 23:54:45 +0100 Subject: 39986, 39989: improve handling of vi-repeat-change Save previous vi change and throw away a new change that fails. Add zle -f vichange to allow shell widget to be a single change. Fix repeat of command where numeric arguments were multiplied. --- ChangeLog | 7 +++ Doc/Zsh/zle.yo | 7 +++ Functions/Zle/vi-pipe | 3 ++ Src/Zle/zle.h | 14 ++++++ Src/Zle/zle_keymap.c | 2 +- Src/Zle/zle_main.c | 34 +++++++++++-- Src/Zle/zle_misc.c | 8 ++- Src/Zle/zle_thingy.c | 11 +++- Src/Zle/zle_utils.c | 1 + Src/Zle/zle_vi.c | 137 +++++++++++++++++++++++--------------------------- Test/X02zlevi.ztst | 10 ++-- 11 files changed, 147 insertions(+), 87 deletions(-) (limited to 'Src/Zle/zle_utils.c') diff --git a/ChangeLog b/ChangeLog index 1095a1e5c..24fb8a3f3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2016-11-20 Oliver Kiddle + * 39986, 39989: Src/Zle/zle.h, Src/Zle/zle_keymap.c, + Src/Zle/zle_main.c, Src/Zle/zle_misc.c, Src/Zle/zle_thingy.c, + Src/Zle/zle_utils.c, Src/Zle/zle_vi.c, Test/X02zlevi.ztst, + Doc/Zsh/zle.yo, Functions/Zle/vi-pipe: make vi-repeat-change + work better with shell based widgets and save old change + when recording a new change in case the new one fails + * 39974: Completion/Unix/Command/_ssh: complete shared libraries for -e and -s options to ssh-add diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index fe6a7e93b..ff3144802 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -479,6 +479,13 @@ tt(kill) for indicating that text has been killed into the cutbuffer. When repeatedly invoking a kill widget, text is appended to the cutbuffer instead of replacing it, but when wrapping such widgets, it is necessary to call `tt(zle -f kill)' to retain this effect. + +tt(vichange) for indicating that the widget represents a vi change that +can be repeated as a whole with `tt(vi-repeat-change)'. The flag should be set +early in the function before inspecting the value of tt(NUMERIC) or invoking +other widgets. This has no effect for a widget invoked from insert mode. If +insert mode is active when the widget finishes, the change extends until next +returning to command mode. ) cindex(completion widgets, creating) item(tt(-C) var(widget) var(completion-widget) var(function))( diff --git a/Functions/Zle/vi-pipe b/Functions/Zle/vi-pipe index c32e64a59..1729cb6e1 100644 --- a/Functions/Zle/vi-pipe +++ b/Functions/Zle/vi-pipe @@ -12,6 +12,9 @@ setopt localoptions noksharrays autoload -Uz read-from-minibuffer local _save_cut="$CUTBUFFER" REPLY +# mark this widget as a vi change so it can be repeated as a whole +zle -f vichange + # force movement to default to line mode (( REGION_ACTIVE )) || zle -U V # Use the standard vi-change to accept a vi motion. diff --git a/Src/Zle/zle.h b/Src/Zle/zle.h index e9b14281d..8f92e5611 100644 --- a/Src/Zle/zle.h +++ b/Src/Zle/zle.h @@ -284,6 +284,20 @@ struct change { #define CH_NEXT (1<<0) /* next structure is also part of this change */ #define CH_PREV (1<<1) /* previous structure is also part of this change */ +/* vi change handling for vi-repeat-change */ + +/* + * Examination of the code suggests vichgbuf is consistently tied + * to raw byte input, so it is left as a character array rather + * than turned into wide characters. In particular, when we replay + * it we use ungetbytes(). + */ +struct vichange { + struct modifier mod; /* value of zmod associated with vi change */ + char *buf; /* bytes for keys that make up the vi command */ + int bufsz, bufptr; /* allocated and in use sizes of buf */ +}; + /* known thingies */ #define Th(X) (&thingies[X]) diff --git a/Src/Zle/zle_keymap.c b/Src/Zle/zle_keymap.c index 24e8d1964..04eb70675 100644 --- a/Src/Zle/zle_keymap.c +++ b/Src/Zle/zle_keymap.c @@ -1634,7 +1634,7 @@ getkeymapcmd(Keymap km, Thingy *funcp, char **strp) unmetafy(keybuf + lastlen, &keybuflen); ungetbytes(keybuf+lastlen, keybuflen); if(vichgflag) - vichgbufptr -= keybuflen; + curvichg.bufptr -= keybuflen; keybuf[keybuflen = lastlen] = 0; } *funcp = func; diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c index 1652b7cd4..938dc0e29 100644 --- a/Src/Zle/zle_main.c +++ b/Src/Zle/zle_main.c @@ -924,13 +924,13 @@ getbyte(long do_keytmout, int *timeout) ret = STOUC(cc); } /* - * vichgbuf is raw bytes, not wide characters, so is dealt + * curvichg.buf is raw bytes, not wide characters, so is dealt * with here. */ if (vichgflag) { - if (vichgbufptr == vichgbufsz) - vichgbuf = realloc(vichgbuf, vichgbufsz *= 2); - vichgbuf[vichgbufptr++] = ret; + if (curvichg.bufptr == curvichg.bufsz) + curvichg.buf = realloc(curvichg.buf, curvichg.bufsz *= 2); + curvichg.buf[curvichg.bufptr++] = ret; } errno = old_errno; return lastchar = ret; @@ -1260,6 +1260,7 @@ zleread(char **lp, char **rp, int flags, int context, char *init, char *finish) *zleline = ZWC('\0'); virangeflag = lastcmd = done = zlecs = zlell = mark = yankb = yanke = 0; vichgflag = 0; + viinrepeat = 0; viinsbegin = 0; statusline = NULL; selectkeymap("main", 1); @@ -1389,6 +1390,8 @@ int execzlefunc(Thingy func, char **args, int set_bindk) { int r = 0, ret = 0, remetafy = 0; + int nestedvichg = vichgflag; + int isrepeat = (viinrepeat == 3); Widget w; Thingy save_bindk = bindk; @@ -1398,6 +1401,8 @@ execzlefunc(Thingy func, char **args, int set_bindk) unmetafy_line(); remetafy = 1; } + if (isrepeat) + viinrepeat = 2; if (func->flags & DISABLED) { /* this thingy is not the name of a widget */ @@ -1523,6 +1528,25 @@ execzlefunc(Thingy func, char **args, int set_bindk) CCRIGHT(); if (remetafy) metafy_line(); + + /* if this widget constituted the vi change, end it */ + if (vichgflag == 2 && !nestedvichg) { + if (invicmdmode()) { + if (ret) { + free(curvichg.buf); + } else { + if (lastvichg.buf) + free(lastvichg.buf); + lastvichg = curvichg; + } + vichgflag = 0; + curvichg.buf = NULL; + } else + vichgflag = 1; /* vi change continues while in insert mode */ + } + if (isrepeat) + viinrepeat = !invicmdmode(); + return ret; } @@ -2230,7 +2254,7 @@ finish_(UNUSED(Module m)) cleanup_keymaps(); deletehashtable(thingytab); - zfree(vichgbuf, vichgbufsz); + zfree(lastvichg.buf, lastvichg.bufsz); zfree(kungetbuf, kungetsz); free_isrch_spots(); if (rdstrs) diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c index fbd40cd03..898b552de 100644 --- a/Src/Zle/zle_misc.c +++ b/Src/Zle/zle_misc.c @@ -609,8 +609,10 @@ viputbefore(UNUSED(char **args)) int n = zmult; startvichange(-1); - if (n < 0 || zmod.flags & MOD_NULL) + if (n < 0) return 1; + if (zmod.flags & MOD_NULL) + return 0; if (zmod.flags & MOD_VIBUF) kctbuf = &vibuf[zmod.vibuf]; else @@ -630,8 +632,10 @@ viputafter(UNUSED(char **args)) int n = zmult; startvichange(-1); - if (n < 0 || zmod.flags & MOD_NULL) + if (n < 0) return 1; + if (zmod.flags & MOD_NULL) + return 0; if (zmod.flags & MOD_VIBUF) kctbuf = &vibuf[zmod.vibuf]; else diff --git a/Src/Zle/zle_thingy.c b/Src/Zle/zle_thingy.c index 2d4674785..c7092854a 100644 --- a/Src/Zle/zle_thingy.c +++ b/Src/Zle/zle_thingy.c @@ -678,7 +678,16 @@ bin_zle_flags(char *name, char **args, UNUSED(Options ops), UNUSED(char func)) else if (!strcmp(*flag, "keepsuffix")) w->flags |= ZLE_KEEPSUFFIX; */ - else { + else if (!strcmp(*flag, "vichange")) { + if (invicmdmode()) { + startvichange(-1); + if (zmod.flags & (MOD_MULT|MOD_TMULT)) { + Param pm = (Param) paramtab->getnode(paramtab, "NUMERIC"); + if (pm && pm->node.flags & PM_SPECIAL) + pm->node.flags &= ~PM_UNSET; + } + } + } else { zwarnnam(name, "invalid flag `%s' given to zle -f", *flag); ret = 1; } diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c index 4007c1112..c6df3d89c 100644 --- a/Src/Zle/zle_utils.c +++ b/Src/Zle/zle_utils.c @@ -1704,6 +1704,7 @@ mergeundo(void) current->flags |= CH_PREV; current->prev->flags |= CH_NEXT; } + vistartchange = -1; } /* diff --git a/Src/Zle/zle_vi.c b/Src/Zle/zle_vi.c index fc0e49b32..e0923db3e 100644 --- a/Src/Zle/zle_vi.c +++ b/Src/Zle/zle_vi.c @@ -45,46 +45,41 @@ int wordflag; /**/ int vilinerange; -/* last vi change buffer, for vi change repetition */ +/* + * lastvichg: last vi change buffer, for vi change repetition + * curvichg: current incomplete vi change + */ + +/**/ +struct vichange lastvichg, curvichg; /* - * vichgbufsz: Allocated size of vichgbuf. - * vichgbufptr: Length in use. - * vichgflag: true whilst inputting a vi normal mode; causes it to be - * accumulated in vichgbuf, incrementing vichgbufptr. + * true whilst a vi change is active causing keys to be + * accumulated in curvichg.buf + * first set to 2 and when the initial widget finishes, reduced to 1 if + * in insert mode implying that the change continues until returning to + * normal mode */ /**/ -int vichgbufsz, vichgbufptr, vichgflag; +int vichgflag; /* - * The bytes that make up the current vi command. See vichgbuf* above. - * - * Examination of the code suggests vichgbuf is consistently tied - * to raw byte input, so it is left as a character array rather - * than turned into wide characters. In particular, when we replay - * it we use ungetbytes(). + * analogous to vichgflag for a repeated change with the value following + * a similar pattern (is 3 until first repeated widget starts) */ + /**/ -char *vichgbuf; +int viinrepeat; /* point where vi insert mode was last entered */ /**/ int viinsbegin; -/* value of zmod associated with vi change */ -static struct modifier lastmod; - -/* - * inrepeat: current widget is the vi change being repeated - * vichgrepeat: nested widget call within a repeat - */ -static int inrepeat, vichgrepeat; - /** * im: >= 0: is an insertmode - * -1: skip setting insert mode + * -1: skip setting insert/overwrite mode * -2: entering viins at start of editing from clean --- don't use * inrepeat or keybuf, synthesise an entry to insert mode. * Note that zmult is updated so this should be called before zmult is used. @@ -94,30 +89,27 @@ static int inrepeat, vichgrepeat; void startvichange(int im) { - if (im != -1) { - vichgflag = 1; - if (im > -1) - insmode = im; - } - if (inrepeat && im != -2) { - zmod = lastmod; - inrepeat = vichgflag = 0; - vichgrepeat = 1; - } else { - lastmod = zmod; - if (vichgbuf) - free(vichgbuf); - vichgbuf = (char *)zalloc(vichgbufsz = 16 + keybuflen); + if (im > -1) + insmode = im; + if (viinrepeat && im != -2) { + zmod = lastvichg.mod; + vichgflag = 0; + } else if (!vichgflag) { + curvichg.mod = zmod; + if (curvichg.buf) + free(curvichg.buf); + curvichg.buf = (char *)zalloc(curvichg.bufsz = 16 + keybuflen); if (im == -2) { - vichgbuf[0] = + vichgflag = 1; + curvichg.buf[0] = zlell ? (insmode ? (zlecs < zlell ? 'i' : 'a') : 'R') : 'o'; - vichgbuf[1] = '\0'; - vichgbufptr = 1; + curvichg.buf[1] = '\0'; + curvichg.bufptr = 1; } else { - strcpy(vichgbuf, keybuf); - unmetafy(vichgbuf, &vichgbufptr); + vichgflag = 2; + strcpy(curvichg.buf, keybuf); + unmetafy(curvichg.buf, &curvichg.bufptr); } - vichgrepeat = 0; } } @@ -226,10 +218,13 @@ getvirange(int wf) */ if ((k2 == bindk) ? dovilinerange() : execzlefunc(k2, zlenoargs, 1)) ret = -1; - if(vichgrepeat) + if (viinrepeat) zmult = mult1; - else + else { zmult = mult1 * zmod.tmult; + if (vichgflag == 2) + curvichg.mod.mult = zmult; + } } while(prefixflag && !ret); wordflag = 0; selectlocalmap(NULL); @@ -401,7 +396,6 @@ videlete(UNUSED(char **args)) vifirstnonblank(zlenoargs); } } - vichgflag = 0; return ret; } @@ -518,7 +512,6 @@ viyank(UNUSED(char **args)) cut(zlecs, c2 - zlecs, CUT_YANK); ret = 0; } - vichgflag = 0; /* cursor now at the start of the range yanked. For line mode * restore the column position */ if (vilinerange && lastcol != -1) { @@ -593,8 +586,7 @@ vireplace(UNUSED(char **args)) * a change, we always read the argument normally, even if the count * * was bad. When recording a change for repeating, and a bad count is * * given, we squash the repeat buffer to avoid repeating the partial * - * command; we've lost the previous change, but that can't be avoided * - * without a rewrite of the repeat code. */ + * command. */ /**/ int @@ -644,18 +636,12 @@ vireplacechars(UNUSED(char **args)) /* check argument range */ if (n < 1 || fail) { - if(vichgrepeat) + if (viinrepeat) vigetkey(); - if(vichgflag) { - free(vichgbuf); - vichgbuf = NULL; - vichgflag = 0; - } return 1; } /* get key */ if((ch = vigetkey()) == ZLEEOF) { - vichgflag = 0; return 1; } /* do change */ @@ -682,7 +668,6 @@ vireplacechars(UNUSED(char **args)) zleline[zlecs++] = ch; zlecs--; } - vichgflag = 0; return 0; } @@ -693,7 +678,16 @@ vicmdmode(UNUSED(char **args)) if (invicmdmode() || selectkeymap("vicmd", 0)) return 1; mergeundo(); - vichgflag = 0; + insmode = unset(OVERSTRIKE); + if (vichgflag == 1) { + vichgflag = 0; + if (lastvichg.buf) + free(lastvichg.buf); + lastvichg = curvichg; + curvichg.buf = NULL; + } + if (viinrepeat == 1) + viinrepeat = 0; if (zlecs != findbol()) DECCS(); return 0; @@ -748,7 +742,6 @@ vioperswapcase(UNUSED(char **args)) vifirstnonblank(); #endif } - vichgflag = 0; return ret; } @@ -771,7 +764,6 @@ viupcase(UNUSED(char **args)) zlecs = oldcs; ret = 0; } - vichgflag = 0; return ret; } @@ -794,7 +786,6 @@ vidowncase(UNUSED(char **args)) zlecs = oldcs; ret = 0; } - vichgflag = 0; return ret; } @@ -803,23 +794,23 @@ int virepeatchange(UNUSED(char **args)) { /* make sure we have a change to repeat */ - if (!vichgbuf || vichgflag || virangeflag) + if (!lastvichg.buf || vichgflag || virangeflag) return 1; /* restore or update the saved count and buffer */ if (zmod.flags & MOD_MULT) { - lastmod.mult = zmod.mult; - lastmod.flags |= MOD_MULT; + lastvichg.mod.mult = zmod.mult; + lastvichg.mod.flags |= MOD_MULT; } if (zmod.flags & MOD_VIBUF) { - lastmod.vibuf = zmod.vibuf; - lastmod.flags = (lastmod.flags & ~MOD_VIAPP) | + lastvichg.mod.vibuf = zmod.vibuf; + lastvichg.mod.flags = (lastvichg.mod.flags & ~MOD_VIAPP) | MOD_VIBUF | (zmod.flags & MOD_VIAPP); - } else if (lastmod.flags & MOD_VIBUF && - lastmod.vibuf >= 27 && lastmod.vibuf <= 34) - lastmod.vibuf++; /* for "1 to "8 advance to next buffer */ + } else if (lastvichg.mod.flags & MOD_VIBUF && + lastvichg.mod.vibuf >= 27 && lastvichg.mod.vibuf <= 34) + lastvichg.mod.vibuf++; /* for "1 to "8 advance to next buffer */ /* repeat the command */ - inrepeat = 1; - ungetbytes(vichgbuf, vichgbufptr); + viinrepeat = 3; + ungetbytes(lastvichg.buf, lastvichg.bufptr); return 0; } @@ -835,10 +826,8 @@ viindent(UNUSED(char **args)) region_active = 2; /* get the range */ if ((c2 = getvirange(0)) == -1) { - vichgflag = 0; return 1; } - vichgflag = 0; /* must be a line range */ if (!vilinerange) { zlecs = oldcs; @@ -873,10 +862,8 @@ viunindent(UNUSED(char **args)) region_active = 2; /* get the range */ if ((c2 = getvirange(0)) == -1) { - vichgflag = 0; return 1; } - vichgflag = 0; /* must be a line range */ if (!vilinerange) { zlecs = oldcs; diff --git a/Test/X02zlevi.ztst b/Test/X02zlevi.ztst index c19573241..d3b533490 100644 --- a/Test/X02zlevi.ztst +++ b/Test/X02zlevi.ztst @@ -140,6 +140,12 @@ >BUFFER: xxe xxx xxxee >CURSOR: 10 + zletest $'one two three four five six seven eight\e.03d2wk.1.' +0:numeric args to both action and movement are multiplied (and saved for any repeat) +>BUFFER: eight +>seven eight +>CURSOR: 0 + zletest $'yankee doodle\ebhDyy0"1P' 0:paste register 1 to get last deletion >BUFFER: doodleyankee @@ -262,10 +268,8 @@ print -u $ZTST_fd 'This test may hang the shell when it fails...' zletest $'worm\erdhd..' 0:use of vi-repeat as the motion and repeat after a failed change ->BUFFER: word +>BUFFER: wodd >CURSOR: 2 -F:For vi compatibility, "." should repeat the "rd" change after "d." -F:Update result to ">BUFFER: wodd" if compatibility is repaired. zpty_run 'bindkey "^_" undo' zletest $'undoc\037e' -- cgit v1.2.3