int copyprevword(UNUSED(char **args)) { int len, t0 = zlecs, t1; if (zmult > 0) { int count = zmult; for (;;) { t1 = t0; while (t0) { int prev = t0; DECPOS(prev); if (ZC_iword(zleline[prev])) break; t0 = prev; } while (t0) { int prev = t0; DECPOS(prev); if (!ZC_iword(zleline[prev])) break; t0 = prev; } if (!--count) break; if (t0 == 0) return 1; } } else return 1; len = t1 - t0; spaceinline(len); ZS_memcpy(zleline + zlecs, zleline + t0, len); zlecs += len; return 0; }
int gosmacstransposechars(UNUSED(char **args)) { if (zlecs < 2 || zleline[zlecs - 1] == '\n' || zleline[zlecs - 2] == '\n') { int twice = (zlecs == 0 || zleline[zlecs - 1] == '\n'); if (zlecs == zlell || zleline[zlecs] == '\n') return 1; INCCS(); if (twice) { if (zlecs == zlell || zleline[zlecs] == '\n') return 1; INCCS(); } } #ifdef MULTIBYTE_SUPPORT { int start, middle; middle = zlecs; DECPOS(middle); start = middle; DECPOS(start); transpose_swap(start, middle, zlecs); } #else { ZLE_CHAR_T cc = zleline[zlecs - 2]; zleline[zlecs - 2] = zleline[zlecs - 1]; zleline[zlecs - 1] = cc; } #endif return 0; }
int vijoin(UNUSED(char **args)) { int x, pos; int n = zmult; int visual = region_active; startvichange(-1); if (n < 1) return 1; if (visual && zlecs > mark) { exchangepointandmark(zlenoargs); x = findeol(); if (x >= mark) { exchangepointandmark(zlenoargs); return 1; } } else if ((x = findeol()) == zlell || (visual && x >= mark)) return 1; while (n) { zlecs = x + 1; pos = zlecs; for (; zlecs != zlell && ZC_iblank(zleline[zlecs]); INCPOS(zlecs)) ; x = 1 + (zlecs - pos); backdel(x, CUT_RAW); if (zlecs) { int pos = zlecs; DECPOS(pos); if (ZC_iblank(zleline[pos])) { zlecs = pos; return 0; } } spaceinline(1); zleline[zlecs] = ZWC(' '); if ((!visual && --n < 2) || (x = findeol()) == zlell || (visual && x >= mark)) return 0; } return 0; }
int vibackwardword(char **args) { int n = zmult; if (n < 0) { int ret; zmult = -n; ret = viforwardword(args); zmult = n; return ret; } while (n--) { int nl = 0; while (zlecs) { DECCS(); if (!ZC_inblank(zleline[zlecs])) break; nl += (zleline[zlecs] == ZWC('\n')); if (nl == 2) { INCCS(); break; } } if (zlecs) { int pos = zlecs; int cc = wordclass(zleline[pos]); for (;;) { zlecs = pos; if (zlecs == 0) break; DECPOS(pos); if (wordclass(zleline[pos]) != cc || ZC_inblank(zleline[pos])) break; } } } return 0; }
int transposewords(UNUSED(char **args)) { int p1, p2, p3, p4, pt, len, x = zlecs, pos; ZLE_STRING_T temp, pp; int n = zmult; int neg = n < 0, ocs = zlecs; if (neg) n = -n; while (x != zlell && zleline[x] != ZWC('\n') && !ZC_iword(zleline[x])) INCPOS(x); if (x == zlell || zleline[x] == ZWC('\n')) { x = zlecs; while (x) { if (ZC_iword(zleline[x])) break; pos = x; DECPOS(pos); if (zleline[pos] == ZWC('\n')) break; x = pos; } if (!x) return 1; pos = x; DECPOS(pos); if (zleline[pos] == ZWC('\n')) return 1; } for (p4 = x; p4 != zlell && ZC_iword(zleline[p4]); INCPOS(p4)) ; for (p3 = p4; p3; ) { pos = p3; DECPOS(pos); if (!ZC_iword(zleline[pos])) break; p3 = pos; } if (!p3) return 1; p1 = p2 = pt = p3; while (n--) { for (p2 = pt; p2; ) { pos = p2; DECPOS(pos); if (ZC_iword(zleline[pos])) break; p2 = pos; } if (!p2) return 1; for (p1 = p2; p1; ) { pos = p1; DECPOS(pos); if (!ZC_iword(zleline[pos])) break; p1 = pos; } pt = p1; } pp = temp = (ZLE_STRING_T)zhalloc((p4 - p1)*ZLE_CHAR_SIZE); len = p4 - p3; ZS_memcpy(pp, zleline + p3, len); pp += len; len = p3 - p2; ZS_memcpy(pp, zleline + p2, len); pp += len; ZS_memcpy(pp, zleline + p1, p2 - p1); ZS_memcpy(zleline + p1, temp, p4 - p1); if (neg) zlecs = ocs; else zlecs = p4; return 0; }
static int getvirange(int wf) { int pos = zlecs, mpos = mark, ret = 0; int visual = region_active; /* movement command might set it */ int mult1 = zmult, hist1 = histline; Thingy k2; if (visual) { if (!zlell) return -1; pos = mark; vilinerange = (visual == 2); region_active = 0; } else { virangeflag = 1; wordflag = wf; mark = -1; /* use operator-pending keymap if one exists */ Keymap km = openkeymap("viopp"); if (km) selectlocalmap(km); /* Now we need to execute the movement command, to see where it * * actually goes. virangeflag here indicates to the movement * * function that it should place the cursor at the end of the * * range, rather than where the cursor would actually go if it * * were executed normally. This makes a difference to some * * commands, but not all. For example, if searching forward * * for a character, under normal circumstances the cursor lands * * on the character. For a range, the range must include the * * character, so the cursor gets placed after the character if * * virangeflag is set. */ zmod.flags &= ~MOD_TMULT; do { vilinerange = 0; prefixflag = 0; if (!(k2 = getkeycmd()) || (k2->flags & DISABLED) || k2 == Th(z_sendbreak)) { wordflag = 0; virangeflag = 0; mark = mpos; return -1; } /* * 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, 1)) ret = -1; if(vichgrepeat) zmult = mult1; else zmult = mult1 * zmod.tmult; } while(prefixflag && !ret); wordflag = 0; selectlocalmap(NULL); /* 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 || zlell != lastll || memcmp(zleline, lastline, zlell)) { histline = hist1; ZS_memcpy(zleline, lastline, zlell = lastll); zlecs = pos; mark = mpos; virangeflag = 0; return -1; } /* Can't handle an empty file. Also, if the movement command * * failed, or didn't move, it is an error. */ if (!zlell || (zlecs == pos && (mark == -1 || mark == zlecs) && virangeflag != 2) || ret == -1) { mark = mpos; virangeflag = 0; return -1; } virangeflag = 0; /* if the mark has moved, ignore the original cursor position * * and use the mark. */ if (mark != -1) pos = mark; } mark = mpos; /* Get the range the right way round. zlecs is placed at the * * start of the range, and pos (the return value of this * * function) is the end. */ if (zlecs > pos) { int tmp = zlecs; zlecs = pos; pos = tmp; } /* visual selection mode needs to include additional position */ if (visual == 1 && pos < zlell && invicmdmode()) INCPOS(pos); /* Was it a line-oriented move? If so, the command will have set * * the vilinerange flag. In this case, entire lines are taken, * * rather than just the sequence of characters delimited by pos * * and zlecs. The terminating newline is left out of the range, * * which the real command must deal with appropriately. At this * * point we just need to make the range encompass entire lines. */ vilinerange = (zmod.flags & MOD_LINE) || (vilinerange && !(zmod.flags & MOD_CHAR)); if (vilinerange) { int newcs = findbol(); lastcol = zlecs - newcs; zlecs = pos; pos = findeol(); zlecs = newcs; } else if (!visual) { /* for a character-wise move don't include a newline at the * * end of the range */ int prev = pos; DECPOS(prev); if (zleline[prev] == ZWC('\n')) pos = prev; } return pos; }