int viputafter(UNUSED(char **args)) { Cutbuffer buf = &cutbuf; int n = zmult; startvichange(-1); if (n < 0) return 1; if (zmod.flags & MOD_VIBUF) buf = &vibuf[zmod.vibuf]; if (!buf->buf) return 1; if(buf->flags & CUTBUFFER_LINE) { zlecs = findeol(); spaceinline(buf->len + 1); zleline[zlecs++] = ZWC('\n'); ZS_memcpy(zleline + zlecs, buf->buf, buf->len); vifirstnonblank(zlenoargs); } else { if (zlecs != findeol()) INCCS(); while (n--) { spaceinline(buf->len); ZS_memcpy(zleline + zlecs, buf->buf, buf->len); zlecs += buf->len; } if (zlecs) DECCS(); } return 0; }
void viputafter(void) { Cutbuffer buf = &cutbuf; startvichange(-1); if (zmult < 0) return; if (gotvibufspec) buf = &vibuf[vibufspec]; if (!buf->buf) { feep(); return; } vilinerange = !!(buf->flags & CUTBUFFER_LINE); if (vilinerange) { cs = findeol(); spaceinline(buf->len + 1); line[cs++] = '\n'; memcpy((char *)line + cs, buf->buf, buf->len); vifirstnonblank(); } else { if (cs != findeol()) cs++; while (zmult--) { spaceinline(buf->len); memcpy((char *)line + cs, buf->buf, buf->len); cs += buf->len; } if (cs) cs--; } }
int poundinsert(UNUSED(char **args)) { zlecs = 0; vifirstnonblank(zlenoargs); if (zleline[zlecs] != '#') { spaceinline(1); zleline[zlecs] = '#'; zlecs = findeol(); while(zlecs != zlell) { zlecs++; vifirstnonblank(zlenoargs); spaceinline(1); zleline[zlecs] = '#'; zlecs = findeol(); } } else { foredel(1, 0); zlecs = findeol(); while(zlecs != zlell) { zlecs++; vifirstnonblank(zlenoargs); if(zleline[zlecs] == '#') foredel(1, 0); zlecs = findeol(); } } done = 1; return 0; }
void selfinsert() /**/ { int ncs = cs+mult; if (mult < 0) { mult = -mult; ncs = cs; } if (insmode || ll == cs) spaceinline(mult); else if (mult+cs > ll) spaceinline(ll-(mult+cs)); while (mult--) line[cs++] = c; cs = ncs; }
int viindent(UNUSED(char **args)) { int oldcs = zlecs, c2; /* get the range */ startvichange(1); if ((c2 = getvirange(0)) == -1) { vichgflag = 0; return 1; } vichgflag = 0; /* must be a line range */ if (!vilinerange) { zlecs = oldcs; return 1; } oldcs = zlecs; /* add a tab to the beginning of each line within range */ while (zlecs < c2) { spaceinline(1); zleline[zlecs] = '\t'; zlecs = findeol() + 1; } /* go back to the first line of the range */ zlecs = oldcs; vifirstnonblank(zlenoargs); return 0; }
int viquotedinsert(char **args) { #ifndef HAS_TIO struct sgttyb sob; #endif spaceinline(1); zleline[zlecs] = '^'; zrefresh(); #ifndef HAS_TIO sob = shttyinfo.sgttyb; sob.sg_flags = (sob.sg_flags | RAW) & ~ECHO; ioctl(SHTTY, TIOCSETN, &sob); #endif getfullchar(0); #ifndef HAS_TIO zsetterm(); #endif foredel(1, 0); if(LASTFULLCHAR == ZLEEOF) return 1; else return selfinsert(args); }
void yank() /**/ { int cc; char *buf = cutbuf; if (!cutbuf) { feep(); return; } if (mult < 0) return; if (vibufspec) { vibufspec = tolower(vibufspec); vibufspec += (idigit(vibufspec)) ? -'1'+26 : -'a'; if (!(buf = vibuf[vibufspec])) { feep(); vibufspec = 0; return; } vibufspec = 0; } yankb = cs; while (mult--) { kct = kringnum; cc = strlen(buf); spaceinline(cc); strncpy((char *) line+cs,buf,cc); cs += cc; yanke = cs; } }
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 viquotedinsert(void) { #ifndef WINNT #ifndef HAS_TIO struct sgttyb sob; #endif #endif /* WINNT */ spaceinline(1); line[cs] = '^'; refresh(); #ifndef WINNT #ifndef HAS_TIO sob = shttyinfo.sgttyb; sob.sg_flags = (sob.sg_flags | RAW) & ~ECHO; ioctl(SHTTY, TIOCSETN, &sob); #endif #endif /* WINNT */ c = getkey(0); #ifndef WINNT #ifndef HAS_TIO setterm(); #endif #endif /* WINNT */ foredel(1); if(c < 0) feep(); else selfinsert(); }
int copyprevshellword(UNUSED(char **args)) { LinkList l; LinkNode n; int i; char *p = NULL; if (zmult <= 0) return 1; if ((l = bufferwords(NULL, NULL, &i, LEXFLAGS_ZLE))) { i -= (zmult-1); if (i < 0) return 1; for (n = firstnode(l); n; incnode(n)) if (!i--) { p = getdata(n); break; } } if (p) { int len; ZLE_STRING_T lineadd = stringaszleline(p, 0, &len, NULL, NULL); spaceinline(len); ZS_memcpy(zleline + zlecs, lineadd, len); zlecs += len; free(lineadd); } return 0; }
int quoteregion(UNUSED(char **args)) { ZLE_STRING_T str; size_t len; int extra = invicmdmode(); if (mark > zlell) mark = zlell; if (region_active == 2) { int a, b; regionlines(&a, &b); zlecs = a; mark = b; extra = 0; } else if (mark < zlecs) { int tmp = mark; mark = zlecs; zlecs = tmp; } if (extra) INCPOS(mark); str = (ZLE_STRING_T)hcalloc((len = mark - zlecs) * ZLE_CHAR_SIZE); ZS_memcpy(str, zleline + zlecs, len); foredel(len, CUT_RAW); str = makequote(str, &len); spaceinline(len); ZS_memcpy(zleline + zlecs, str, len); mark = zlecs; zlecs += len; return 0; }
void viindent(void) { int oldcs = cs, c2; /* get the range */ startvichange(1); if ((c2 = getvirange(0)) == -1) { vichgflag = vilinerange = 0; return; } vichgflag = 0; /* must be a line range */ if (!vilinerange) { feep(); cs = oldcs; return; } vilinerange = 0; oldcs = cs; /* add a tab to the beginning of each line within range */ while (cs < c2) { spaceinline(1); line[cs] = '\t'; cs = findeol() + 1; } /* go back to the first line of the range */ cs = oldcs; vifirstnonblank(); }
int vijoin(UNUSED(char **args)) { int x, pos; startvichange(-1); if ((x = findeol()) == zlell) return 1; 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(' '); return 0; }
int vipoundinsert(UNUSED(char **args)) { int oldcs = zlecs; startvichange(-1); vifirstnonblank(zlenoargs); if(zleline[zlecs] != '#') { spaceinline(1); zleline[zlecs] = '#'; if(zlecs <= viinsbegin) INCPOS(viinsbegin); if (zlecs <= oldcs) INCPOS(oldcs); zlecs = oldcs; } else { foredel(1, 0); if (zlecs < viinsbegin) DECPOS(viinsbegin); if (zlecs < oldcs) DECPOS(oldcs); zlecs = oldcs; } return 0; }
/* position: 0 is before, 1 after, 2 split the line */ static void pastebuf(Cutbuffer buf, int mult, int position) { int cc; if (buf->flags & CUTBUFFER_LINE) { if (position == 2) { if (!zlecs) position = 0; else if (zlecs == zlell) position = 1; } if (position == 2) { yankb = zlecs; spaceinline(buf->len + 2); zleline[zlecs++] = ZWC('\n'); ZS_memcpy(zleline + zlecs, buf->buf, buf->len); zlecs += buf->len; zleline[zlecs] = ZWC('\n'); yanke = zlecs + 1; } else if (position != 0) { yankb = zlecs = findeol(); spaceinline(buf->len + 1); zleline[zlecs++] = ZWC('\n'); yanke = zlecs + buf->len; ZS_memcpy(zleline + zlecs, buf->buf, buf->len); } else { yankb = zlecs = findbol(); spaceinline(buf->len + 1); ZS_memcpy(zleline + zlecs, buf->buf, buf->len); yanke = zlecs + buf->len + 1; zleline[zlecs + buf->len] = ZWC('\n'); } vifirstnonblank(zlenoargs); } else { if (position == 1 && zlecs != findeol()) INCCS(); yankb = zlecs; cc = buf->len; while (mult--) { spaceinline(cc); ZS_memcpy(zleline + zlecs, buf->buf, cc); zlecs += cc; } yanke = zlecs; if (zlecs && invicmdmode()) DECCS(); } }
void viopenlineabove(void) { cs = findbol(); spaceinline(1); line[cs] = '\n'; startvitext(1); }
void viopenlinebelow(void) { cs = findeol(); spaceinline(1); line[cs++] = '\n'; startvitext(1); }
int yankpop(UNUSED(char **args)) { int cc, kctstart = kct; Cutbuffer buf; if (!(lastcmd & ZLE_YANK) || !kring || !kctbuf) { kctbuf = NULL; return 1; } do { /* * This is supposed to make the yankpop loop * original buffer -> kill ring in order -> original buffer -> ... * where the original buffer is -1 and the remainder are * indices into the kill ring, remember that we need to start * that at kringnum rather than zero. */ if (kct == -1) kct = kringnum; else { int kctnew = (kct + kringsize - 1) % kringsize; if (kctnew == kringnum) kct = -1; else kct = kctnew; } if (kct == -1) buf = kctbuf; /* Use original cutbuffer */ else buf = kring+kct; /* Use somewhere in the kill ring */ /* Careful to prevent infinite looping */ if (kct == kctstart) return 1; /* * Skip unset buffers instead of stopping as we used to do. * Also skip zero-length buffers. * There are two reasons for this: * 1. We now map the array $killring directly into the * killring, instead of via some extra size-checking logic. * When $killring has been set, a buffer will always have * at least a zero-length string in it. * 2. The old logic was inconsistent; when the kill ring * was full, we could loop round and round it, otherwise * we just stopped when we hit the first empty buffer. */ } while (!buf->buf || *buf->buf == ZWC('\0')); zlecs = yankb; foredel(yanke - yankb, CUT_RAW); cc = buf->len; spaceinline(cc); ZS_memcpy(zleline + zlecs, buf->buf, cc); zlecs += cc; yanke = zlecs; return 0; }
void insertlastword(void) { int n; char *s, *t; int len; Histent he; /* multiple calls will now search back through the history, pem */ static char *lastinsert; static int lasthist, lastpos; int evhist = curhist - 1, save; if (lastinsert) { int lastlen = ztrlen(lastinsert); int pos = cs; if (lastpos <= pos && lastlen == pos - lastpos && memcmp(lastinsert, (char *)&line[lastpos], lastlen) == 0) { evhist = --lasthist; cs = lastpos; foredel(pos - cs); } zsfree(lastinsert); lastinsert = NULL; } if (!(he = quietgethist(evhist)) || !he->nwords) { feep(); return; } if (zmult > 0) { n = he->nwords - (zmult - 1); } else { n = 1 - zmult; } if (n < 1 || n > he->nwords) { feep(); return; } s = he->text + he->words[2*n-2]; t = he->text + he->words[2*n-1]; save = *t; *t = '\0'; /* ignore trailing whitespace */ lasthist = evhist; lastpos = cs; lastinsert = ztrdup(s); spaceinline(len = ztrlen(s)); while (len--) { line[cs++] = *s == Meta ? *++s ^ 32 : *s; s++; } *t = save; }
int viopenlinebelow(UNUSED(char **args)) { zlecs = findeol(); spaceinline(1); zleline[zlecs++] = '\n'; startvitext(1); clearlist = 1; return 0; }
int viopenlineabove(UNUSED(char **args)) { zlecs = findbol(); spaceinline(1); zleline[zlecs] = '\n'; startvitext(1); clearlist = 1; return 0; }
void poundinsert() /**/ { if (*line != '#') { cs = 0; spaceinline(1); *line = '#'; } else { cs = 0; foredel(1); } done = 1; }
void viputafter() /**/ { int cc; char *buf = cutbuf; if (!cutbuf) { feep(); return; } if (mult < 0) return; if (vibufspec) { vibufspec = tolower(vibufspec); vibufspec += (idigit(vibufspec)) ? -'1'+26 : -'a'; if (!(buf = vibuf[vibufspec])) { feep(); vibufspec = 0; return; } vibufspec = 0; } if (strchr(buf,'\n')) { cs = findeol(); if (cs == ll) { spaceinline(1); line[cs] = '\n'; } } if (cs != ll) cs++; yankb = cs; while (mult--) { kct = kringnum; cc = strlen(buf); spaceinline(cc); strncpy((char *) line+cs,buf,cc); cs += cc; yanke = cs; } cs = yankb; }
void copyprevword() /**/ { int len,t0; for (t0 = cs-1; t0 >= 0; t0--) if (iword(line[t0])) break; for (; t0 >= 0; t0--) if (!iword(line[t0])) break; if (t0) t0++; len = cs-t0; spaceinline(len); strncpy((char *) line+cs,(char *) line+t0,len); cs += len; }
void yankpop() /**/ { int cc; if (!(lastcmd & ZLE_YANK) || !kring[kct]) { feep(); return; } cs = yankb; foredel(yanke-yankb); cc = strlen(kring[kct]); spaceinline(cc); strncpy((char *) line+cs,kring[kct],cc); cs += cc; yanke = cs; kct = (kct-1) & (KRINGCT-1); }
void getline(void) { char *s = (char *)getlinknode(bufstack); if (!s) feep(); else { int cc; unmetafy(s, &cc); spaceinline(cc); memcpy((char *)line + cs, s, cc); cs += cc; free(s); clearlist = 1; } }
static int applychange(struct change *ch) { if(ch->hist != histline) { zle_setline(quietgethist(ch->hist)); zlecs = ch->old_cs; return 0; } zlecs = ch->off; if(ch->del) foredel(ch->dell, CUT_RAW); if(ch->ins) { spaceinline(ch->insl); ZS_memcpy(zleline + zlecs, ch->ins, ch->insl); zlecs += ch->insl; } zlecs = ch->new_cs; return 1; }
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; }
void vijoin(void) { int x; startvichange(-1); if ((x = findeol()) == ll) { feep(); return; } cs = x + 1; for (x = 1; cs != ll && iblank(line[cs]); cs++, x++); backdel(x); if (cs && iblank(line[cs-1])) cs--; else { spaceinline(1); line[cs] = ' '; } }
void vipoundinsert(void) { int oldcs = cs; startvichange(-1); vifirstnonblank(); if(line[cs] != '#') { spaceinline(1); line[cs] = '#'; if(cs <= viinsbegin) viinsbegin++; cs = oldcs + (cs <= oldcs); } else { foredel(1); if (cs < viinsbegin) viinsbegin--; cs = oldcs - (cs < oldcs); } }