예제 #1
0
파일: zle_vi.c 프로젝트: jackleaks/zsh
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;
}
예제 #2
0
파일: zle_misc.c 프로젝트: MPOWER4RU/zsh
int
putreplaceselection(UNUSED(char **args))
{
    int n = zmult;
    struct cutbuffer prevbuf;
    Cutbuffer putbuf;
    int clear = 0;
    int pos = 2;

    startvichange(-1);
    if (n < 0 || zmod.flags & MOD_NULL)
	return 1;
    putbuf = (zmod.flags & MOD_VIBUF) ? &vibuf[zmod.vibuf] : &cutbuf;
    if (!putbuf->buf)
	return 1;
    memcpy(&prevbuf, putbuf, sizeof(prevbuf));

    /* if "9 was specified, prevent killregion from freeing it */
    if (zmod.vibuf == 35) {
	putbuf->buf = 0;
	clear = 1;
    }

    zmod.flags = 0; /* flags apply to paste not kill */
    if (region_active == 2 && prevbuf.flags & CUTBUFFER_LINE) {
	int a, b;
	regionlines(&a, &b);
	pos = (b == zlell);
    }
    killregion(zlenoargs);

    pastebuf(&prevbuf, n, pos);
    if (clear)
	free(prevbuf.buf);
    return 0;
}
예제 #3
0
파일: zle_vi.c 프로젝트: jackleaks/zsh
int
vireplacechars(UNUSED(char **args))
{
    ZLE_INT_T ch;
    int n = zmult, fail = 0, newchars = 0;

    if (n > 0) {
	if (region_active) {
	    int a, b;
	    if (region_active == 1) {
		if (mark > zlecs) {
		    a = zlecs;
		    b = mark;
		} else {
		    a = mark;
		    b = zlecs;
		}
		INCPOS(b);
	    } else
		regionlines(&a, &b);
	    zlecs = a;
	    if (b > zlell)
		b = zlell;
	    n = b - a;
	    while (a < b) {
		newchars++;
		INCPOS(a);
            }
	    region_active = 0;
	} else {
	    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.
	 * With a selection this will replace newlines which vim
	 * doesn't do but this simplifies things a lot.
	 */
	if (n > newchars)
	    shiftchars(zlecs, n - newchars);
	else if (n < newchars)
	    spaceinline(newchars - n);
	while (newchars--)
	    zleline[zlecs++] = ch;
	zlecs--;
    }
    vichgflag = 0;
    return 0;
}