mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-05 23:11:11 +02:00
33700: new widget for put in vim style visual selection mode
This commit is contained in:
parent
c95c2ac838
commit
0ea8f28e7b
5 changed files with 70 additions and 5 deletions
|
@ -1,5 +1,9 @@
|
||||||
2014-11-17 Oliver Kiddle <opk@zsh.org>
|
2014-11-17 Oliver Kiddle <opk@zsh.org>
|
||||||
|
|
||||||
|
* 33700: Doc/Zsh/zle.yo, Src/Zle/iwidgets.list,
|
||||||
|
Src/Zle/zle_misc.c, Src/Zle/zle_utils.c: new widget
|
||||||
|
for put in vim style visual selection mode
|
||||||
|
|
||||||
* 33699: Test/X02zlevi.ztst, Test/comptest: support short
|
* 33699: Test/X02zlevi.ztst, Test/comptest: support short
|
||||||
delays in zle tests where we need KEYTIMEOUT to elapse
|
delays in zle tests where we need KEYTIMEOUT to elapse
|
||||||
|
|
||||||
|
|
|
@ -1721,6 +1721,13 @@ Insert the contents of the kill buffer after the cursor.
|
||||||
If the kill buffer contains a sequence of lines (as opposed to characters),
|
If the kill buffer contains a sequence of lines (as opposed to characters),
|
||||||
paste it below the current line.
|
paste it below the current line.
|
||||||
)
|
)
|
||||||
|
tindex(put-replace-selection)
|
||||||
|
item(tt(put-replace-selection) (unbound) (unbound) (unbound))(
|
||||||
|
Replace the contents of the current region or selection with the
|
||||||
|
contents of the kill buffer. If the kill buffer contains a sequence of
|
||||||
|
lines (as opposed to characters), the current line will be split by the
|
||||||
|
pasted lines.
|
||||||
|
)
|
||||||
tindex(quoted-insert)
|
tindex(quoted-insert)
|
||||||
item(tt(quoted-insert) (^V) (unbound) (unbound))(
|
item(tt(quoted-insert) (^V) (unbound) (unbound))(
|
||||||
Insert the next character typed into the buffer literally.
|
Insert the next character typed into the buffer literally.
|
||||||
|
|
|
@ -89,6 +89,7 @@
|
||||||
"push-input", pushinput, 0
|
"push-input", pushinput, 0
|
||||||
"push-line", pushline, 0
|
"push-line", pushline, 0
|
||||||
"push-line-or-edit", pushlineoredit, 0
|
"push-line-or-edit", pushlineoredit, 0
|
||||||
|
"put-replace-selection", putreplaceselection, ZLE_KEEPSUFFIX
|
||||||
"quoted-insert", quotedinsert, ZLE_MENUCMP | ZLE_KEEPSUFFIX
|
"quoted-insert", quotedinsert, ZLE_MENUCMP | ZLE_KEEPSUFFIX
|
||||||
"quote-line", quoteline, 0
|
"quote-line", quoteline, 0
|
||||||
"quote-region", quoteregion, 0
|
"quote-region", quoteregion, 0
|
||||||
|
|
|
@ -507,11 +507,26 @@ yank(UNUSED(char **args))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pastebuf(Cutbuffer buf, int mult, int after)
|
/* position: 0 is before, 1 after, 2 split the line */
|
||||||
|
static void pastebuf(Cutbuffer buf, int mult, int position)
|
||||||
{
|
{
|
||||||
int cc;
|
int cc;
|
||||||
if (buf->flags & CUTBUFFER_LINE) {
|
if (buf->flags & CUTBUFFER_LINE) {
|
||||||
if (after) {
|
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();
|
yankb = zlecs = findeol();
|
||||||
spaceinline(buf->len + 1);
|
spaceinline(buf->len + 1);
|
||||||
zleline[zlecs++] = ZWC('\n');
|
zleline[zlecs++] = ZWC('\n');
|
||||||
|
@ -526,7 +541,7 @@ static void pastebuf(Cutbuffer buf, int mult, int after)
|
||||||
}
|
}
|
||||||
vifirstnonblank(zlenoargs);
|
vifirstnonblank(zlenoargs);
|
||||||
} else {
|
} else {
|
||||||
if (after && zlecs != findeol())
|
if (position == 1 && zlecs != findeol())
|
||||||
INCCS();
|
INCCS();
|
||||||
yankb = zlecs;
|
yankb = zlecs;
|
||||||
cc = buf->len;
|
cc = buf->len;
|
||||||
|
@ -583,6 +598,44 @@ viputafter(UNUSED(char **args))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/**/
|
/**/
|
||||||
int
|
int
|
||||||
yankpop(UNUSED(char **args))
|
yankpop(UNUSED(char **args))
|
||||||
|
@ -635,7 +688,7 @@ yankpop(UNUSED(char **args))
|
||||||
zlecs = yankb;
|
zlecs = yankb;
|
||||||
foredel(yanke - yankb, CUT_RAW);
|
foredel(yanke - yankb, CUT_RAW);
|
||||||
zlecs = yankcs;
|
zlecs = yankcs;
|
||||||
pastebuf(buf, 1, lastcmd & ZLE_YANKAFTER);
|
pastebuf(buf, 1, !!(lastcmd & ZLE_YANKAFTER));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -953,7 +953,7 @@ cuttext(ZLE_STRING_T line, int ct, int flags)
|
||||||
} else {
|
} else {
|
||||||
/* Save in "1, shifting "1-"8 along to "2-"9 */
|
/* Save in "1, shifting "1-"8 along to "2-"9 */
|
||||||
int n;
|
int n;
|
||||||
free(vibuf[34].buf);
|
free(vibuf[35].buf);
|
||||||
for(n=35; n>27; n--)
|
for(n=35; n>27; n--)
|
||||||
vibuf[n] = vibuf[n-1];
|
vibuf[n] = vibuf[n-1];
|
||||||
vibuf[27].buf = (ZLE_STRING_T)zalloc(ct * ZLE_CHAR_SIZE);
|
vibuf[27].buf = (ZLE_STRING_T)zalloc(ct * ZLE_CHAR_SIZE);
|
||||||
|
|
Loading…
Reference in a new issue