int killregion(UNUSED(char **args)) { if (mark > zlell) mark = zlell; if (region_active == 2) { int a, b; regionlines(&a, &b); zlecs = a; region_active = 0; cut(zlecs, b - zlecs, CUT_RAW); shiftchars(zlecs, b - zlecs); if (zlell) { if (zlecs == zlell) DECCS(); foredel(1, 0); vifirstnonblank(zlenoargs); } } else if (mark > zlecs) { if (invicmdmode()) INCPOS(mark); forekill(mark - zlecs, CUT_RAW); } else { if (invicmdmode()) INCCS(); backkill(zlecs - mark, CUT_FRONT|CUT_RAW); } return 0; }
int vireplacechars(UNUSED(char **args)) { ZLE_INT_T ch; int n = zmult, fail = 0, newchars = 0; if (n > 0) { int pos = zlecs; while (n-- > 0) { if (pos == zlell || zleline[pos] == ZWC('\n')) { fail = 1; break; } newchars++; INCPOS(pos); } n = pos - zlecs; } startvichange(1); /* check argument range */ if (n < 1 || fail) { if(vichgrepeat) vigetkey(); if(vichgflag) { free(vichgbuf); vichgbuf = NULL; vichgflag = 0; } return 1; } /* get key */ if((ch = vigetkey()) == ZLEEOF) { vichgflag = 0; return 1; } /* do change */ if (ch == ZWC('\r') || ch == ZWC('\n')) { /* <return> handled specially */ zlecs += n - 1; backkill(n - 1, CUT_RAW); zleline[zlecs++] = '\n'; } else { /* * Make sure we delete displayed characters, including * attach combining characters. n includes this as a raw * buffer offset. * Use shiftchars so as not to adjust the cursor position; * we are overwriting anything that remains directly. */ if (n > newchars) shiftchars(zlecs, n - newchars); else if (n < newchars) spaceinline(newchars - n); while (newchars--) zleline[zlecs++] = ch; zlecs--; } vichgflag = 0; return 0; }
void forekill(int ct, int dir) { int i = cs; cut(i, ct, dir); shiftchars(i, ct); }
void backkill(int ct, int dir) { int i = (cs -= ct); cut(i, ct, dir); shiftchars(i, ct); }
mod_export void backdel(int ct, int flags) { if (flags & CUT_RAW) { if (zlemetaline != NULL) { shiftchars(zlemetacs -= ct, ct); } else { shiftchars(zlecs -= ct, ct); CCRIGHT(); } } else { int n = ct, origcs = zlecs; DPUTS(zlemetaline != NULL, "backdel needs CUT_RAW when metafied"); while (n--) DECCS(); shiftchars(zlecs, origcs - zlecs); CCRIGHT(); } }
mod_export void foredel(int ct, int flags) { if (flags & CUT_RAW) { if (zlemetaline != NULL) { shiftchars(zlemetacs, ct); } else if (flags & CUT_RAW) { shiftchars(zlecs, ct); CCRIGHT(); } } else { int origcs = zlecs; int n = ct; DPUTS(zlemetaline != NULL, "foredel needs CUT_RAW when metafied"); while (n--) INCCS(); ct = zlecs - origcs; zlecs = origcs; shiftchars(zlecs, ct); CCRIGHT(); } }
int vichangeeol(UNUSED(char **args)) { int a, b; if (region_active) { regionlines(&a, &b); zlecs = a; region_active = 0; cut(zlecs, b - zlecs, CUT_RAW); shiftchars(zlecs, b - zlecs); } else forekill(findeol() - zlecs, CUT_RAW); startvitext(1); return 0; }
mod_export void backkill(int ct, int flags) { UNMETACHECK(); if (flags & CUT_RAW) { zlecs -= ct; } else { int origcs = zlecs; while (ct--) DECCS(); ct = origcs - zlecs; } cut(zlecs, ct, flags); shiftchars(zlecs, ct); CCRIGHT(); }
mod_export void forekill(int ct, int flags) { int i = zlecs; UNMETACHECK(); if (!(flags & CUT_RAW)) { int n = ct; while (n--) INCCS(); ct = zlecs - i; zlecs = i; } cut(i, ct, flags); shiftchars(i, ct); CCRIGHT(); }
void doinsert(ZLE_STRING_T zstr, int len) { ZLE_STRING_T s; ZLE_CHAR_T c1 = *zstr; /* first character */ int neg = zmult < 0; /* insert *after* the cursor? */ int m = neg ? -zmult : zmult; /* number of copies to insert */ int count; UNMETACHECK(); iremovesuffix(c1, 0); invalidatelist(); /* In overwrite mode, don't replace newlines. */ if (insmode || zleline[zlecs] == ZWC('\n')) spaceinline(m * len); else { int pos = zlecs, diff, i; #ifdef MULTIBYTE_SUPPORT /* * Calculate the number of character positions we are * going to be using. The algorithm is that * anything that shows up as a logical single character * (i.e. even if control, or double width, or with combining * characters) is treated as 1 for the purpose of replacing * what's there already. * * This can cause inserting of a combining character in * places where it should overwrite, such as the start * of a line. However, combining characters aren't * useful there anyway and this doesn't cause any * particular harm. */ for (i = 0, count = 0; i < len * m; i++) { if (!IS_COMBINING(zstr[i])) count++; } #else count = len * m; #endif /* * Ensure we replace a complete combining characterfor each * character we overwrite. Switch to inserting at first newline. */ for (i = count; pos < zlell && zleline[pos] != ZWC('\n') && i--; ) { INCPOS(pos); } /* * Calculate how many raw line places we need. * pos - zlecs is the raw line distance we're replacing, * m * len the number we're inserting. */ diff = pos - zlecs - m * len; if (diff < 0) { spaceinline(-diff); } else if (diff > 0) { /* * We use shiftchars() here because we don't * want combining char alignment fixed up: we * are going to write over any that remain. */ shiftchars(zlecs, diff); } } while (m--) for (s = zstr, count = len; count; s++, count--) zleline[zlecs++] = *s; if (neg) zlecs += zmult * len; /* if we ended up on a combining character, skip over it */ CCRIGHT(); }
void foredel(int ct) { shiftchars(cs, ct); }
void backdel(int ct) { shiftchars(cs -= ct, ct); }