diff options
author | Peter Stephenson <pws@users.sourceforge.net> | 2004-03-08 11:44:09 +0000 |
---|---|---|
committer | Peter Stephenson <pws@users.sourceforge.net> | 2004-03-08 11:44:09 +0000 |
commit | 2ace0ce4f2803367a3006384172136a54118614e (patch) | |
tree | b5d8be867c03a0d7fc05044308e216cc7cd0eb2b /Src/Zle | |
parent | 8db5846e31506ecd0e5a50202411f22725d63e43 (diff) | |
download | zsh-2ace0ce4f2803367a3006384172136a54118614e.tar.gz zsh-2ace0ce4f2803367a3006384172136a54118614e.tar.xz zsh-2ace0ce4f2803367a3006384172136a54118614e.zip |
19553: rename c in zle to lastchar
Diffstat (limited to 'Src/Zle')
-rw-r--r-- | Src/Zle/complist.c | 8 | ||||
-rw-r--r-- | Src/Zle/zle_hist.c | 24 | ||||
-rw-r--r-- | Src/Zle/zle_keymap.c | 8 | ||||
-rw-r--r-- | Src/Zle/zle_main.c | 4 | ||||
-rw-r--r-- | Src/Zle/zle_misc.c | 45 | ||||
-rw-r--r-- | Src/Zle/zle_move.c | 263 | ||||
-rw-r--r-- | Src/Zle/zle_tricky.c | 12 | ||||
-rw-r--r-- | Src/Zle/zle_vi.c | 398 |
8 files changed, 386 insertions, 376 deletions
diff --git a/Src/Zle/complist.c b/Src/Zle/complist.c index ea86d79e9..d43a03677 100644 --- a/Src/Zle/complist.c +++ b/Src/Zle/complist.c @@ -1859,7 +1859,7 @@ msearch(Cmatch **ptr, int ins, int back, int rep, int *wrapp) msearchpush(ptr, back); if (ins) { - s[0] = c; + s[0] = lastchar; s[1] = '\0'; msearchstr = dyncat(msearchstr, s); @@ -2754,9 +2754,9 @@ domenuselect(Hookdef dummy, Chdata dat) } } if (cmd == Th(z_selfinsertunmeta)) { - c &= 0x7f; - if (c == '\r') - c = '\n'; + lastchar &= 0x7f; + if (lastchar == '\r') + lastchar = '\n'; } wrap = 0; np = msearch(p, ins, (ins ? (mode == MM_BSEARCH) : back), diff --git a/Src/Zle/zle_hist.c b/Src/Zle/zle_hist.c index b24db660c..94770b235 100644 --- a/Src/Zle/zle_hist.c +++ b/Src/Zle/zle_hist.c @@ -949,17 +949,17 @@ doisearch(char **args, int dir) sbuf[sbptr] = '^'; zrefresh(); } - if ((c = getkey(0)) == EOF) + if ((lastchar = getkey(0)) == EOF) feep = 1; else goto ins; } else { if(cmd == Th(z_selfinsertunmeta)) { - c &= 0x7f; - if(c == '\r') - c = '\n'; + lastchar &= 0x7f; + if(lastchar == '\r') + lastchar = '\n'; } else if (cmd == Th(z_magicspace)) - c = ' '; + lastchar = ' '; else if (cmd != Th(z_selfinsert)) { ungetkeycmd(); if (cmd == Th(z_sendbreak)) @@ -977,7 +977,7 @@ doisearch(char **args, int dir) sbuf = ibuf + FIRST_SEARCH_CHAR; sibuf *= 2; } - sbuf[sbptr++] = c; + sbuf[sbptr++] = lastchar; } if (feep) handlefeep(zlenoargs); @@ -1091,7 +1091,7 @@ getvisrchstr(void) break; } if(cmd == Th(z_magicspace)) { - c = ' '; + lastchar = ' '; cmd = Th(z_selfinsert); } if(cmd == Th(z_redisplay)) { @@ -1126,15 +1126,15 @@ getvisrchstr(void) sbuf[sptr] = '^'; zrefresh(); } - if ((c = getkey(0)) == EOF) + if ((lastchar = getkey(0)) == EOF) feep = 1; else goto ins; } else if(cmd == Th(z_selfinsertunmeta) || cmd == Th(z_selfinsert)) { if(cmd == Th(z_selfinsertunmeta)) { - c &= 0x7f; - if(c == '\r') - c = '\n'; + lastchar &= 0x7f; + if(lastchar == '\r') + lastchar = '\n'; } ins: if(sptr == ssbuf - 1) { @@ -1142,7 +1142,7 @@ getvisrchstr(void) strcpy(newbuf, sbuf); statusline = sbuf = newbuf; } - sbuf[sptr++] = c; + sbuf[sptr++] = lastchar; } else { feep = 1; } diff --git a/Src/Zle/zle_keymap.c b/Src/Zle/zle_keymap.c index 9f3b9dfd4..f28dec775 100644 --- a/Src/Zle/zle_keymap.c +++ b/Src/Zle/zle_keymap.c @@ -1257,11 +1257,11 @@ getkeymapcmd(Keymap km, Thingy *funcp, char **strp) { Thingy func = t_undefinedkey; char *str = NULL; - int lastlen = 0, lastc = c; + int lastlen = 0, lastc = lastchar; keybuflen = 0; keybuf[0] = 0; - while((c = getkeybuf(!!lastlen)) != EOF) { + while((lastchar = getkeybuf(!!lastlen)) != EOF) { char *s; Thingy f; int loc = 1; @@ -1274,7 +1274,7 @@ getkeymapcmd(Keymap km, Thingy *funcp, char **strp) lastlen = keybuflen; func = f; str = s; - lastc = c; + lastc = lastchar; } if(!keyisprefix((loc ? localkeymap : km), keybuf)) break; @@ -1282,7 +1282,7 @@ getkeymapcmd(Keymap km, Thingy *funcp, char **strp) if(!lastlen && keybuflen) lastlen = keybuflen; else - c = lastc; + lastchar = lastc; if(lastlen != keybuflen) { unmetafy(keybuf + lastlen, &keybuflen); ungetkeys(keybuf+lastlen, keybuflen); diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c index 25d2539dc..2ed250e14 100644 --- a/Src/Zle/zle_main.c +++ b/Src/Zle/zle_main.c @@ -76,7 +76,7 @@ int mark; /* last character pressed */ /**/ -int c; +mod_export int lastchar; /* the bindings for the previous and for this key */ @@ -688,7 +688,7 @@ zlecore(void) selectlocalmap(NULL); bindk = getkeycmd(); if (!ll && isfirstln && !(zlereadflags & ZLRF_IGNOREEOF) && - c == eofchar) { + lastchar == eofchar) { eofsent = 1; break; } diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c index 89c8b8229..bd59653d6 100644 --- a/Src/Zle/zle_misc.c +++ b/Src/Zle/zle_misc.c @@ -62,11 +62,11 @@ selfinsert(char **args) { char s[3], *p = s; - if(imeta(c)) { + if(imeta(lastchar)) { *p++ = Meta; - c ^= 32; + lastchar ^= 32; } - *p++ = c; + *p++ = lastchar; *p = 0; doinsert(s); return 0; @@ -76,9 +76,9 @@ selfinsert(char **args) int selfinsertunmeta(char **args) { - c &= 0x7f; - if (c == '\r') - c = '\n'; + lastchar &= 0x7f; + if (lastchar == '\r') + lastchar = '\n'; return selfinsert(args); } @@ -489,11 +489,11 @@ quotedinsert(char **args) sob.sg_flags = (sob.sg_flags | RAW) & ~ECHO; ioctl(SHTTY, TIOCSETN, &sob); #endif - c = getkey(0); + lastchar = getkey(0); #ifndef HAS_TIO zsetterm(); #endif - if (c < 0) + if (lastchar < 0) return 1; else return selfinsert(args); @@ -506,7 +506,7 @@ digitargument(char **args) int sign = (zmult < 0) ? -1 : 1; /* allow metafied as well as ordinary digits */ - if ((c & 0x7f) < '0' || (c & 0x7f) > '9') + if ((lastchar & 0x7f) < '0' || (lastchar & 0x7f) > '9') return 1; if (!(zmod.flags & MOD_TMULT)) @@ -514,10 +514,10 @@ digitargument(char **args) if (zmod.flags & MOD_NEG) { /* If we just had a negative argument, this is the digit, * * rather than the -1 assumed by negargument() */ - zmod.tmult = sign * (c & 0xf); + zmod.tmult = sign * (lastchar & 0xf); zmod.flags &= ~MOD_NEG; } else - zmod.tmult = zmod.tmult * 10 + sign * (c & 0xf); + zmod.tmult = zmod.tmult * 10 + sign * (lastchar & 0xf); zmod.flags |= MOD_TMULT; prefixflag = 1; return 0; @@ -764,16 +764,16 @@ executenamedcommand(char *prmt) } else if(cmd == Th(z_viquotedinsert)) { *ptr = '^'; zrefresh(); - c = getkey(0); - if(c == EOF || !c || len == NAMLEN) + lastchar = getkey(0); + if(lastchar == EOF || !lastchar || len == NAMLEN) feep = 1; else - *ptr++ = c, len++, curlist = 0; + *ptr++ = lastchar, len++, curlist = 0; } else if(cmd == Th(z_quotedinsert)) { - if((c = getkey(0)) == EOF || !c || len == NAMLEN) + if((lastchar = getkey(0)) == EOF || !lastchar || len == NAMLEN) feep = 1; else - *ptr++ = c, len++, curlist = 0; + *ptr++ = lastchar, len++, curlist = 0; } else if(cmd == Th(z_backwarddeletechar) || cmd == Th(z_vibackwarddeletechar)) { if (len) @@ -811,15 +811,15 @@ executenamedcommand(char *prmt) unrefthingy(r); } if(cmd == Th(z_selfinsertunmeta)) { - c &= 0x7f; - if(c == '\r') - c = '\n'; + lastchar &= 0x7f; + if(lastchar == '\r') + lastchar = '\n'; cmd = Th(z_selfinsert); } if (cmd == Th(z_listchoices) || cmd == Th(z_deletecharorlist) || cmd == Th(z_expandorcomplete) || cmd == Th(z_completeword) || cmd == Th(z_expandorcompleteprefix) || cmd == Th(z_vicmdmode) || - cmd == Th(z_acceptline) || c == ' ' || c == '\t') { + cmd == Th(z_acceptline) || lastchar == ' ' || lastchar == '\t') { cmdambig = 100; cmdll = newlinklist(); @@ -866,10 +866,11 @@ executenamedcommand(char *prmt) len = cmdambig; } } else { - if (len == NAMLEN || icntrl(c) || cmd != Th(z_selfinsert)) + if (len == NAMLEN || icntrl(lastchar) || + cmd != Th(z_selfinsert)) feep = 1; else - *ptr++ = c, len++, curlist = 0; + *ptr++ = lastchar, len++, curlist = 0; } } if (feep) diff --git a/Src/Zle/zle_move.c b/Src/Zle/zle_move.c index 8ed4c657a..a7db7dc85 100644 --- a/Src/Zle/zle_move.c +++ b/Src/Zle/zle_move.c @@ -30,67 +30,72 @@ #include "zle.mdh" #include "zle_move.pro" -static vimarkcs[27], vimarkline[27]; +static int vimarkcs[27], vimarkline[27]; /**/ -void -beginningofline(void) +int +beginningofline(char **args) { int n = zmult; if (n < 0) { + int ret; zmult = -n; - endofline(); + ret = endofline(args); zmult = n; - return; + return ret; } while (n--) { if (cs == 0) - return; + return 0; if (line[cs - 1] == '\n') if (!--cs) - return; + return 0; while (cs && line[cs - 1] != '\n') cs--; } + return 0; } /**/ -void -endofline(void) +int +endofline(char **args) { int n = zmult; if (n < 0) { + int ret; zmult = -n; - beginningofline(); + ret = beginningofline(args); zmult = n; - return; + return ret; } while (n--) { if (cs >= ll) { cs = ll; - return; + return 0; } if (line[cs] == '\n') if (++cs == ll) - return; + return 0; while (cs != ll && line[cs] != '\n') cs++; } + return 0; } /**/ -void -beginningoflinehist(void) +int +beginningoflinehist(char **args) { int n = zmult; if (n < 0) { + int ret; zmult = -n; - endoflinehist(); + ret = endoflinehist(args); zmult = n; - return; + return ret; } while (n) { if (cs == 0) @@ -103,26 +108,29 @@ beginningoflinehist(void) n--; } if (n) { - int m = zmult; + int m = zmult, ret; zmult = n; - uphistory(); + ret = uphistory(args); zmult = m; cs = 0; + return ret; } + return 0; } /**/ -void -endoflinehist(void) +int +endoflinehist(char **args) { int n = zmult; if (n < 0) { + int ret; zmult = -n; - beginningoflinehist(); + ret = beginningoflinehist(args); zmult = n; - return; + return ret; } while (n) { if (cs >= ll) { @@ -137,46 +145,51 @@ endoflinehist(void) n--; } if (n) { - int m = zmult; + int m = zmult, ret; zmult = n; - downhistory(); + ret = downhistory(args); zmult = m; + return ret; } + return 0; } /**/ -void -forwardchar(void) +int +forwardchar(char **args) { cs += zmult; if (cs > ll) cs = ll; if (cs < 0) cs = 0; + return 0; } /**/ -void -backwardchar(void) +int +backwardchar(char **args) { cs -= zmult; if (cs > ll) cs = ll; if (cs < 0) cs = 0; + return 0; } /**/ -void -setmarkcommand(void) +int +setmarkcommand(char **args) { mark = cs; + return 0; } /**/ -void -exchangepointandmark(void) +int +exchangepointandmark(char **args) { int x; @@ -185,11 +198,12 @@ exchangepointandmark(void) cs = x; if (cs > ll) cs = ll; + return 0; } /**/ -void -vigotocolumn(void) +int +vigotocolumn(char **args) { int x, y; @@ -202,20 +216,20 @@ vigotocolumn(void) cs = y; if (cs < x) cs = x; + return 0; } /**/ -void -vimatchbracket(void) +int +vimatchbracket(char **args) { int ocs = cs, dir, ct; unsigned char oth, me; otog: if (cs == ll || line[cs] == '\n') { - feep(); cs = ocs; - return; + return 1; } switch (me = line[cs]) { case '{': @@ -258,49 +272,49 @@ vimatchbracket(void) ct++; } if (cs < 0 || cs >= ll) { - feep(); cs = ocs; + return 1; } else if(dir > 0 && virangeflag) cs++; + return 0; } /**/ -void -viforwardchar(void) +int +viforwardchar(char **args) { int lim = findeol() - invicmdmode(); int n = zmult; if (n < 0) { + int ret; zmult = -n; - vibackwardchar(); + ret = vibackwardchar(args); zmult = n; - return; - } - if (cs >= lim) { - feep(); - return; + return ret; } + if (cs >= lim) + return 1; while (n-- && cs < lim) cs++; + return 0; } /**/ -void -vibackwardchar(void) +int +vibackwardchar(char **args) { int n = zmult; if (n < 0) { + int ret; zmult = -n; - viforwardchar(); + ret = viforwardchar(args); zmult = n; - return; - } - if (cs == findbol()) { - feep(); - return; + return ret; } + if (cs == findbol()) + return 1; while (n--) { cs--; if (cs < 0 || line[cs] == '\n') { @@ -308,195 +322,190 @@ vibackwardchar(void) break; } } + return 0; } /**/ -void -viendofline(void) +int +viendofline(char **args) { int oldcs = cs, n = zmult; - if (n < 1) { - feep(); - return; - } + if (n < 1) + return 1; while(n--) { if (cs > ll) { cs = oldcs; - feep(); - return; + return 1; } cs = findeol() + 1; } cs--; lastcol = 1<<30; + return 0; } /**/ -void -vibeginningofline(void) +int +vibeginningofline(char **args) { cs = findbol(); + return 0; } static int vfindchar, vfinddir, tailadd; /**/ -void -vifindnextchar(void) +int +vifindnextchar(char **args) { if ((vfindchar = vigetkey()) != -1) { vfinddir = 1; tailadd = 0; - virepeatfind(); + return virepeatfind(args); } + return 1; } /**/ -void -vifindprevchar(void) +int +vifindprevchar(char **args) { if ((vfindchar = vigetkey()) != -1) { vfinddir = -1; tailadd = 0; - virepeatfind(); + return virepeatfind(args); } + return 1; } /**/ -void -vifindnextcharskip(void) +int +vifindnextcharskip(char **args) { if ((vfindchar = vigetkey()) != -1) { vfinddir = 1; tailadd = -1; - virepeatfind(); + return virepeatfind(args); } + return 1; } /**/ -void -vifindprevcharskip(void) +int +vifindprevcharskip(char **args) { if ((vfindchar = vigetkey()) != -1) { vfinddir = -1; tailadd = 1; - virepeatfind(); + return virepeatfind(args); } + return 1; } /**/ -void -virepeatfind(void) +int +virepeatfind(char **args) { int ocs = cs, n = zmult; - if (!vfinddir) { - feep(); - return; - } + if (!vfinddir) + return 1; if (n < 0) { + int ret; zmult = -n; - virevrepeatfind(); + ret = virevrepeatfind(args); zmult = n; - return; + return ret; } while (n--) { do cs += vfinddir; while (cs >= 0 && cs < ll && line[cs] != vfindchar && line[cs] != '\n'); if (cs < 0 || cs >= ll || line[cs] == '\n') { - feep(); cs = ocs; - return; + return 1; } } cs += tailadd; if (vfinddir == 1 && virangeflag) cs++; + return 0; } /**/ -void -virevrepeatfind(void) +int +virevrepeatfind(char **args) { + int ret; + if (zmult < 0) { zmult = -zmult; - virepeatfind(); + ret = virepeatfind(args); zmult = -zmult; - return; + return ret; } vfinddir = -vfinddir; - virepeatfind(); + ret = virepeatfind(args); vfinddir = -vfinddir; + return ret; } /**/ -void -vifirstnonblank(void) +int +vifirstnonblank(char **args) { cs = findbol(); while (cs != ll && iblank(line[cs])) cs++; + return 0; } /**/ -void -visetmark(void) +int +visetmark(char **args) { int ch; ch = getkey(0); - if (ch < 'a' || ch > 'z') { - feep(); - return; - } + if (ch < 'a' || ch > 'z') + return 1; ch -= 'a'; vimarkcs[ch] = cs; vimarkline[ch] = histline; + return 0; } /**/ -void -vigotomark(void) +int +vigotomark(char **args) { int ch; ch = getkey(0); - if (ch == c) + if (ch == lastchar) ch = 26; else { - if (ch < 'a' || ch > 'z') { - feep(); - return; - } + if (ch < 'a' || ch > 'z') + return 1; ch -= 'a'; } - if (!vimarkline[ch]) { - feep(); - return; - } - if (curhist != vimarkline[ch]) { - char *s; - - remember_edits(); - if (!(s = qgetevent(vimarkline[ch]))) { - vimarkline[ch] = 0; - feep(); - return; - } - histline = vimarkline[ch]; - setline(s); + if (!vimarkline[ch]) + return 1; + if (curhist != vimarkline[ch] && !zle_goto_hist(vimarkline[ch], 0, 0)) { + vimarkline[ch] = 0; + return 1; } cs = vimarkcs[ch]; if (cs > ll) cs = ll; + return 0; } /**/ -void -vigotomarkline(void) +int +vigotomarkline(char **args) { - vigotomark(); - vifirstnonblank(); + vigotomark(args); + return vifirstnonblank(zlenoargs); } diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c index 7146302ee..57a61adcf 100644 --- a/Src/Zle/zle_tricky.c +++ b/Src/Zle/zle_tricky.c @@ -193,7 +193,7 @@ completeword(char **args) usemenu = !!isset(MENUCOMPLETE); useglob = isset(GLOBCOMPLETE); wouldinstab = 0; - if (c == '\t' && usetab()) + if (lastchar == '\t' && usetab()) return selfinsert(args); else { int ret; @@ -215,7 +215,7 @@ menucomplete(char **args) usemenu = 1; useglob = isset(GLOBCOMPLETE); wouldinstab = 0; - if (c == '\t' && usetab()) + if (lastchar == '\t' && usetab()) return selfinsert(args); else return docomplete(COMP_COMPLETE); @@ -262,7 +262,7 @@ expandword(char **args) { usemenu = useglob = 0; wouldinstab = 0; - if (c == '\t' && usetab()) + if (lastchar == '\t' && usetab()) return selfinsert(args); else return docomplete(COMP_EXPAND); @@ -275,7 +275,7 @@ expandorcomplete(char **args) usemenu = !!isset(MENUCOMPLETE); useglob = isset(GLOBCOMPLETE); wouldinstab = 0; - if (c == '\t' && usetab()) + if (lastchar == '\t' && usetab()) return selfinsert(args); else { int ret; @@ -297,7 +297,7 @@ menuexpandorcomplete(char **args) usemenu = 1; useglob = isset(GLOBCOMPLETE); wouldinstab = 0; - if (c == '\t' && usetab()) + if (lastchar == '\t' && usetab()) return selfinsert(args); else return docomplete(COMP_EXPAND_COMPLETE); @@ -2294,7 +2294,7 @@ magicspace(char **args) { char *bangq; int ret; - c = ' '; + lastchar = ' '; for (bangq = (char *)line; (bangq = strchr(bangq, bangchar)); bangq += 2) if (bangq[1] == '"' && (bangq == (char *)line || bangq[-1] != '\\')) break; diff --git a/Src/Zle/zle_vi.c b/Src/Zle/zle_vi.c index a599d8091..9ba84aadc 100644 --- a/Src/Zle/zle_vi.c +++ b/Src/Zle/zle_vi.c @@ -78,7 +78,7 @@ startvichange(int im) if (vichgbuf) free(vichgbuf); vichgbuf = (char *)zalloc(vichgbufsz = 16); - vichgbuf[0] = c; + vichgbuf[0] = lastchar; vichgbufptr = 1; vichgrepeat = 0; } @@ -102,12 +102,10 @@ vigetkey(void) char m[3], *str; Thingy cmd; - if((c = getkey(0)) == EOF) { - feep(); + if((lastchar = getkey(0)) == EOF) return -1; - } - m[0] = c; + m[0] = lastchar; metafy(m, 1, META_NOALLOC); if(mn) cmd = keybind(mn, m, &str); @@ -115,34 +113,29 @@ vigetkey(void) cmd = t_undefinedkey; if (!cmd || cmd == Th(z_sendbreak)) { - feep(); return -1; } else if (cmd == Th(z_quotedinsert)) { - if ((c = getkey(0)) == EOF) { - feep(); + if ((lastchar = getkey(0)) == EOF) return -1; - } } else if(cmd == Th(z_viquotedinsert)) { char sav = line[cs]; line[cs] = '^'; - refresh(); - c = getkey(0); + zrefresh(); + lastchar = getkey(0); line[cs] = sav; - if(c == EOF) { - feep(); + if(lastchar == EOF) return -1; - } } else if (cmd == Th(z_vicmdmode)) return -1; - return c; + return lastchar; } /**/ static int getvirange(int wf) { - int pos = cs; + int pos = cs, ret = 0; int mult1 = zmult, hist1 = histline; Thingy k2; @@ -168,39 +161,37 @@ getvirange(int wf) k2 == Th(z_sendbreak)) { wordflag = 0; virangeflag = 0; - feep(); return -1; } - if(k2 == bindk) - /* The command key is repeated: a number of lines is used. */ - dovilinerange(); - else - execzlefunc(k2); + /* + * With k2 == bindk, the command key is repeated: + * a number of lines is used. If the function used + * returns 1, we fail. + */ + if ((k2 == bindk) ? dovilinerange() : execzlefunc(k2, zlenoargs)) + ret = -1; if(vichgrepeat) zmult = mult1; else zmult = mult1 * zmod.tmult; - } while(prefixflag); + } while(prefixflag && !ret); wordflag = 0; virangeflag = 0; /* It is an error to use a non-movement command to delimit the * * range. We here reject the case where the command modified * * the line, or selected a different history line. */ - if(histline != hist1 || ll != lastll || memcmp(line, lastline, ll)) { + if (histline != hist1 || ll != lastll || memcmp(line, lastline, ll)) { histline = hist1; memcpy(line, lastline, ll = lastll); cs = pos; - feep(); return -1; } /* Can't handle an empty file. Also, if the movement command * * failed, or didn't move, it is an error. */ - if (!ll || (cs == pos && virangeflag != 2)) { - feep(); + if (!ll || (cs == pos && virangeflag != 2) || ret == -1) return -1; - } /* vi-match-bracket changes the value of virangeflag when * * moving to the opening bracket, meaning that we need to * @@ -233,7 +224,7 @@ getvirange(int wf) } /**/ -static void +static int dovilinerange(void) { int pos = cs, n = zmult; @@ -243,17 +234,14 @@ dovilinerange(void) * downward, otherwise upward. The repeat count gives the * * number of lines. */ vilinerange = 1; - if (!n) { - feep(); - return; - } + if (!n) + return 1; if (n > 0) { while(n-- && cs <= ll) cs = findeol() + 1; if (n != -1) { cs = pos; - feep(); - return; + return 1; } cs--; } else { @@ -261,123 +249,127 @@ dovilinerange(void) cs = findbol() - 1; if (n != 1) { cs = pos; - feep(); - return; + return 1; } cs++; } virangeflag = 2; + return 0; } /**/ -void -viaddnext(void) +int +viaddnext(char **args) { if (cs != findeol()) cs++; startvitext(1); + return 0; } /**/ -void -viaddeol(void) +int +viaddeol(char **args) { cs = findeol(); startvitext(1); + return 0; } /**/ -void -viinsert(void) +int +viinsert(char **args) { startvitext(1); + return 0; } /**/ -void -viinsertbol(void) +int +viinsertbol(char **args) { - vifirstnonblank(); + vifirstnonblank(zlenoargs); startvitext(1); + return 0; } /**/ -void -videlete(void) +int +videlete(char **args) { - int c2; + int c2, ret = 1; startvichange(1); if ((c2 = getvirange(0)) != -1) { forekill(c2 - cs, 0); + ret = 0; if (vilinerange && ll) { if (cs == ll) cs--; foredel(1); - vifirstnonblank(); + vifirstnonblank(zlenoargs); } } vichgflag = 0; + return ret; } /**/ -void -videletechar(void) +int +videletechar(char **args) { int n = zmult; startvichange(-1); /* handle negative argument */ if (n < 0) { + int ret; zmult = -n; - vibackwarddeletechar(); + ret = vibackwarddeletechar(args); zmult = n; - return; + return ret; } /* it is an error to be on the end of line */ - if (cs == ll || line[cs] == '\n') { - feep(); - return; - } + if (cs == ll || line[cs] == '\n') + return 1; /* Put argument into the acceptable range -- it is not an error to * * specify a greater count than the number of available characters. */ if (n > findeol() - cs) n = findeol() - cs; /* do the deletion */ forekill(n, 0); + return 0; } /**/ -void -vichange(void) +int +vichange(char **args) { - int c2; + int c2, ret = 1; startvichange(1); if ((c2 = getvirange(1)) != -1) { + ret = 0; forekill(c2 - cs, 0); selectkeymap("main", 1); viinsbegin = cs; undoing = 0; } + return ret; } /**/ -void -visubstitute(void) +int +visubstitute(char **args) { int n = zmult; startvichange(1); - if (n < 0) { - feep(); - return; - } + if (n < 0) + return 1; /* it is an error to be on the end of line */ - if (cs == ll || line[cs] == '\n') { - feep(); - return; - } + if (cs == ll || line[cs] == '\n') + return 1; /* Put argument into the acceptable range -- it is not an error to * * specify a greater count than the number of available characters. */ if (n > findeol() - cs) @@ -385,79 +377,84 @@ visubstitute(void) /* do the substitution */ forekill(n, 0); startvitext(1); + return 0; } /**/ -void -vichangeeol(void) +int +vichangeeol(char **args) { forekill(findeol() - cs, 0); startvitext(1); + return 0; } /**/ -void -vichangewholeline(void) +int +vichangewholeline(char **args) { - vifirstnonblank(); - vichangeeol(); + vifirstnonblank(args); + return vichangeeol(zlenoargs); } /**/ -void -viyank(void) +int +viyank(char **args) { - int oldcs = cs, c2; + int oldcs = cs, c2, ret = 1; startvichange(1); - if ((c2 = getvirange(0)) != -1) + if ((c2 = getvirange(0)) != -1) { cut(cs, c2 - cs, 0); + ret = 0; + } vichgflag = 0; cs = oldcs; + return ret; } /**/ -void -viyankeol(void) +int +viyankeol(char **args) { int x = findeol(); startvichange(-1); - if (x == cs) { - feep(); - return; - } + if (x == cs) + return 1; cut(cs, x - cs, 0); + return 0; } /**/ -void -viyankwholeline(void) +int +viyankwholeline(char **args) { int bol = findbol(), oldcs = cs; int n = zmult; startvichange(-1); if (n < 1) - return; + return 1; while(n--) { if (cs > ll) { - feep(); cs = oldcs; - return; + return 1; } cs = findeol() + 1; } vilinerange = 1; cut(bol, cs - bol - 1, 0); cs = oldcs; + return 0; } /**/ -void -vireplace(void) +int +vireplace(char **args) { startvitext(0); + return 0; } /* vi-replace-chars has some oddities relating to vi-repeat-change. In * @@ -474,32 +471,27 @@ vireplace(void) * without a rewrite of the repeat code. */ /**/ -void -vireplacechars(void) +int +vireplacechars(char **args) { int ch, n = zmult; startvichange(1); /* check argument range */ if (n < 1 || n + cs > findeol()) { - if(vichgrepeat) { - int ofeep = feepflag; + if(vichgrepeat) vigetkey(); - feepflag = ofeep; - } if(vichgflag) { free(vichgbuf); vichgbuf = NULL; vichgflag = 0; } - feep(); - return; + return 1; } /* get key */ if((ch = vigetkey()) == -1) { vichgflag = 0; - feep(); - return; + return 1; } /* do change */ if (ch == '\r' || ch == '\n') { @@ -513,45 +505,51 @@ vireplacechars(void) cs--; } vichgflag = 0; + return 0; } /**/ -void -vicmdmode(void) +int +vicmdmode(char **args) { if (invicmdmode() || selectkeymap("vicmd", 0)) - feep(); + return 1; undoing = 1; vichgflag = 0; if (cs != findbol()) cs--; + return 0; } /**/ -void -viopenlinebelow(void) +int +viopenlinebelow(char **args) { cs = findeol(); spaceinline(1); line[cs++] = '\n'; startvitext(1); + clearlist = 1; + return 0; } /**/ -void -viopenlineabove(void) +int +viopenlineabove(char **args) { cs = findbol(); spaceinline(1); line[cs] = '\n'; startvitext(1); + clearlist = 1; + return 0; } /**/ -void -vioperswapcase(void) +int +vioperswapcase(char **args) { - int oldcs, c2; + int oldcs, c2, ret = 1; /* get the range */ startvichange(1); @@ -567,20 +565,22 @@ vioperswapcase(void) } /* go back to the first line of the range */ cs = oldcs; + ret = 0; +#if 0 vifirstnonblank(); +#endif } vichgflag = 0; + return ret; } /**/ -void -virepeatchange(void) +int +virepeatchange(char **args) { /* make sure we have a change to repeat */ - if (!vichgbuf || vichgflag) { - feep(); - return; - } + if (!vichgbuf || vichgflag) + return 1; /* restore or update the saved count and buffer */ if (zmod.flags & MOD_MULT) { lastmod.mult = zmod.mult; @@ -594,11 +594,12 @@ virepeatchange(void) /* repeat the command */ inrepeat = 1; ungetkeys(vichgbuf, vichgbufptr); + return 0; } /**/ -void -viindent(void) +int +viindent(char **args) { int oldcs = cs, c2; @@ -606,14 +607,13 @@ viindent(void) startvichange(1); if ((c2 = getvirange(0)) == -1) { vichgflag = 0; - return; + return 1; } vichgflag = 0; /* must be a line range */ if (!vilinerange) { - feep(); cs = oldcs; - return; + return 1; } oldcs = cs; /* add a tab to the beginning of each line within range */ @@ -624,12 +624,13 @@ viindent(void) } /* go back to the first line of the range */ cs = oldcs; - vifirstnonblank(); + vifirstnonblank(zlenoargs); + return 0; } /**/ -void -viunindent(void) +int +viunindent(char **args) { int oldcs = cs, c2; @@ -637,14 +638,13 @@ viunindent(void) startvichange(1); if ((c2 = getvirange(0)) == -1) { vichgflag = 0; - return; + return 1; } vichgflag = 0; /* must be a line range */ if (!vilinerange) { - feep(); cs = oldcs; - return; + return 1; } oldcs = cs; /* remove a tab from the beginning of each line within range */ @@ -655,12 +655,13 @@ viunindent(void) } /* go back to the first line of the range */ cs = oldcs; - vifirstnonblank(); + vifirstnonblank(zlenoargs); + return 0; } /**/ -void -vibackwarddeletechar(void) +int +vibackwarddeletechar(char **args) { int n = zmult; @@ -668,16 +669,16 @@ vibackwarddeletechar(void) startvichange(-1); /* handle negative argument */ if (n < 0) { + int ret; zmult = -n; - videletechar(); + ret = videletechar(args); zmult = n; - return; + return ret; } /* It is an error to be at the beginning of the line, or (in * * insert mode) to delete past the beginning of insertion. */ if ((!invicmdmode() && cs - n < viinsbegin) || cs == findbol()) { - feep(); - return; + return 1; } /* Put argument into the acceptable range -- it is not an error to * * specify a greater count than the number of available characters. */ @@ -685,41 +686,39 @@ vibackwarddeletechar(void) n = cs - findbol(); /* do the deletion */ backkill(n, 1); + return 0; } /**/ -void -vikillline(void) +int +vikillline(char **args) { - if (viinsbegin > cs) { - feep(); - return; - } + if (viinsbegin > cs) + return 1; backdel(cs - viinsbegin); + return 0; } /**/ -void -viputbefore(void) +int +viputbefore(char **args) { Cutbuffer buf = &cutbuf; int n = zmult; startvichange(-1); if (n < 0) - return; + return 1; if (zmod.flags & MOD_VIBUF) buf = &vibuf[zmod.vibuf]; - if (!buf->buf) { - feep(); - return; - } + if (!buf->buf) + return 1; if(buf->flags & CUTBUFFER_LINE) { cs = findbol(); spaceinline(buf->len + 1); memcpy((char *)line + cs, buf->buf, buf->len); line[cs + buf->len] = '\n'; - vifirstnonblank(); + vifirstnonblank(zlenoargs); } else { while (n--) { spaceinline(buf->len); @@ -729,30 +728,29 @@ viputbefore(void) if (cs) cs--; } + return 0; } /**/ -void -viputafter(void) +int +viputafter(char **args) { Cutbuffer buf = &cutbuf; int n = zmult; startvichange(-1); if (n < 0) - return; + return 1; if (zmod.flags & MOD_VIBUF) buf = &vibuf[zmod.vibuf]; - if (!buf->buf) { - feep(); - return; - } + if (!buf->buf) + return 1; if(buf->flags & CUTBUFFER_LINE) { cs = findeol(); spaceinline(buf->len + 1); line[cs++] = '\n'; memcpy((char *)line + cs, buf->buf, buf->len); - vifirstnonblank(); + vifirstnonblank(zlenoargs); } else { if (cs != findeol()) cs++; @@ -764,20 +762,18 @@ viputafter(void) if (cs) cs--; } - + return 0; } /**/ -void -vijoin(void) +int +vijoin(char **args) { int x; startvichange(-1); - if ((x = findeol()) == ll) { - feep(); - return; - } + if ((x = findeol()) == ll) + return 1; cs = x + 1; for (x = 1; cs != ll && iblank(line[cs]); cs++, x++); backdel(x); @@ -787,17 +783,18 @@ vijoin(void) spaceinline(1); line[cs] = ' '; } + return 0; } /**/ -void -viswapcase(void) +int +viswapcase(char **args) { int eol, n = zmult; startvichange(-1); if (n < 1) - return; + return 1; eol = findeol(); while (cs < eol && n--) { if (islower(line[cs])) @@ -808,32 +805,33 @@ viswapcase(void) } if (cs && cs == eol) cs--; + return 0; } /**/ -void -vicapslockpanic(void) +int +vicapslockpanic(char **args) { - beep(); + clearlist = 1; + zbeep(); statusline = "press a lowercase key to continue"; statusll = strlen(statusline); - refresh(); + zrefresh(); while (!islower(getkey(0))); statusline = NULL; + return 0; } /**/ -void -visetbuffer(void) +int +visetbuffer(char **args) { int ch; if ((zmod.flags & MOD_VIBUF) || (((ch = getkey(0)) < '1' || ch > '9') && - (ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z'))) { - feep(); - return; - } + (ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z'))) + return 1; if (ch >= 'A' && ch <= 'Z') /* needed in cut() */ zmod.flags |= MOD_VIAPP; else @@ -841,32 +839,33 @@ visetbuffer(void) zmod.vibuf = tulower(ch) + (idigit(ch) ? -'1' + 26 : -'a'); zmod.flags |= MOD_VIBUF; prefixflag = 1; + return 0; } /**/ -void -vikilleol(void) +int +vikilleol(char **args) { int n = findeol() - cs; startvichange(-1); if (!n) { /* error -- line already empty */ - feep(); - return; + return 1; } /* delete to end of line */ forekill(findeol() - cs, 0); + return 0; } /**/ -void -vipoundinsert(void) +int +vipoundinsert(char **args) { int oldcs = cs; startvichange(-1); - vifirstnonblank(); + vifirstnonblank(zlenoargs); if(line[cs] != '#') { spaceinline(1); line[cs] = '#'; @@ -879,11 +878,12 @@ vipoundinsert(void) viinsbegin--; cs = oldcs - (cs < oldcs); } + return 0; } /**/ -void -viquotedinsert(void) +int +viquotedinsert(char **args) { #ifndef HAS_TIO struct sgttyb sob; @@ -891,35 +891,35 @@ viquotedinsert(void) spaceinline(1); line[cs] = '^'; - refresh(); + zrefresh(); #ifndef HAS_TIO sob = shttyinfo.sgttyb; sob.sg_flags = (sob.sg_flags | RAW) & ~ECHO; ioctl(SHTTY, TIOCSETN, &sob); #endif - c = getkey(0); + lastchar = getkey(0); #ifndef HAS_TIO - setterm(); + zsetterm(); #endif foredel(1); - if(c < 0) - feep(); + if(lastchar < 0) + return 1; else - selfinsert(); + return selfinsert(args); } /* the 0 key in vi: continue a repeat count in the manner of * * digit-argument if possible, otherwise do vi-beginning-of-line. */ /**/ -void -vidigitorbeginningofline(void) +int +vidigitorbeginningofline(char **args) { if(zmod.flags & MOD_TMULT) - digitargument(); + return digitargument(args); else { removesuffix(); invalidatelist(); - vibeginningofline(); + return vibeginningofline(args); } } |