mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-10 12:40:58 +02:00
33518: add support for "_ vi buffer and arguments to vi-set-buffer from a zle widget
This commit is contained in:
parent
72c666fb4f
commit
bdedf7b40b
6 changed files with 105 additions and 18 deletions
|
@ -1,5 +1,9 @@
|
|||
2014-10-23 Oliver Kiddle <opk@zsh.org>
|
||||
|
||||
* 33518: Doc/Zsh/zle.yo, Src/Zle/zle.h, Src/Zle/zle_utils.c,
|
||||
Src/Zle/zle_vi.c, Test/X02zlevi.ztst: add support for "_ vi
|
||||
buffer and arguments to vi-set-buffer from a zle widget
|
||||
|
||||
* 33514: Src/Zle/zle_utils.c: even with a named vi buffer, we
|
||||
should update the default buffer
|
||||
|
||||
|
|
|
@ -2180,19 +2180,29 @@ command. tt(run-help) is normally aliased to tt(man).
|
|||
tindex(vi-set-buffer)
|
||||
item(tt(vi-set-buffer) (unbound) (") (unbound))(
|
||||
Specify a buffer to be used in the following command.
|
||||
There are 35 buffers that can be specified:
|
||||
the 26 `named' buffers tt("a) to tt("z)
|
||||
and the nine `queued' buffers tt("1) to tt("9). The named buffers can also
|
||||
be specified as tt("A) to tt("Z).
|
||||
There are 37 buffers that can be specified:
|
||||
the 26 `named' buffers tt("a) to tt("z), the `yank' buffer tt("0),
|
||||
the nine `queued' buffers tt("1) to tt("9) and the `black hole' buffer
|
||||
tt("_). The named buffers can also be specified as tt("A) to tt("Z).
|
||||
|
||||
When a buffer is specified for a cut command, the text being cut replaces
|
||||
the previous contents of the specified buffer. If a named buffer
|
||||
is specified using a capital, the newly cut text is appended to the buffer
|
||||
instead of overwriting it.
|
||||
When a buffer is specified for a cut, change or yank command, the text
|
||||
concerned replaces the previous contents of the specified buffer. If
|
||||
a named buffer is specified using a capital, the newly cut text is
|
||||
appended to the buffer instead of overwriting it. When using the tt("_)
|
||||
buffer, nothing happens. This can be useful for deleting text without
|
||||
affecting the normal registers.
|
||||
|
||||
If no buffer is specified for a cut command, tt("1) is used, and the
|
||||
contents of tt("1) to tt("8) are each shifted along one buffer; the contents of
|
||||
tt("9) is lost.
|
||||
If no buffer is specified for a cut or change command, tt("1) is used, and
|
||||
the contents of tt("1) to tt("8) are each shifted along one buffer;
|
||||
the contents of tt("9) is lost. If no buffer is specified for a yank
|
||||
command, tt("0") is used. Finally, a paste command without a specified
|
||||
buffer will paste the text from the most recent command regardless of any
|
||||
buffer that might have been used with that command.
|
||||
|
||||
When called from a widget function by the tt(zle) command, the buffer
|
||||
can optionally be specified with an argument. For example,
|
||||
|
||||
example(zle vi-set-buffer A)
|
||||
)
|
||||
tindex(vi-set-mark)
|
||||
item(tt(vi-set-mark) (unbound) (m) (unbound))(
|
||||
|
|
|
@ -240,6 +240,7 @@ struct modifier {
|
|||
#define MOD_VIBUF (1<<2) /* a vi cut buffer has been selected */
|
||||
#define MOD_VIAPP (1<<3) /* appending to the vi cut buffer */
|
||||
#define MOD_NEG (1<<4) /* last command was negate argument */
|
||||
#define MOD_NULL (1<<5) /* throw away text for the vi cut buffer */
|
||||
|
||||
/* current modifier status */
|
||||
|
||||
|
|
|
@ -914,7 +914,7 @@ cut(int i, int ct, int flags)
|
|||
void
|
||||
cuttext(ZLE_STRING_T line, int ct, int flags)
|
||||
{
|
||||
if (!ct)
|
||||
if (!ct || zmod.flags & MOD_NULL)
|
||||
return;
|
||||
|
||||
UNMETACHECK();
|
||||
|
|
|
@ -782,7 +782,7 @@ viputbefore(UNUSED(char **args))
|
|||
int n = zmult;
|
||||
|
||||
startvichange(-1);
|
||||
if (n < 0)
|
||||
if (n < 0 || zmod.flags & MOD_NULL)
|
||||
return 1;
|
||||
if (zmod.flags & MOD_VIBUF)
|
||||
buf = &vibuf[zmod.vibuf];
|
||||
|
@ -814,7 +814,7 @@ viputafter(UNUSED(char **args))
|
|||
int n = zmult;
|
||||
|
||||
startvichange(-1);
|
||||
if (n < 0)
|
||||
if (n < 0 || zmod.flags & MOD_NULL)
|
||||
return 1;
|
||||
if (zmod.flags & MOD_VIBUF)
|
||||
buf = &vibuf[zmod.vibuf];
|
||||
|
@ -905,14 +905,26 @@ vicapslockpanic(UNUSED(char **args))
|
|||
|
||||
/**/
|
||||
int
|
||||
visetbuffer(UNUSED(char **args))
|
||||
visetbuffer(char **args)
|
||||
{
|
||||
ZLE_INT_T ch;
|
||||
|
||||
if ((zmod.flags & MOD_VIBUF) ||
|
||||
(((ch = getfullchar(0)) < ZWC('0') || ch > ZWC('9')) &&
|
||||
if (*args) {
|
||||
ch = **args;
|
||||
if (args[1] || (ch && (*args)[1]))
|
||||
return 1;
|
||||
} else {
|
||||
ch = getfullchar(0);
|
||||
}
|
||||
if (ch == ZWC('_')) {
|
||||
zmod.flags |= MOD_NULL;
|
||||
prefixflag = 1;
|
||||
return 0;
|
||||
} else
|
||||
zmod.flags &= ~MOD_NULL;
|
||||
if ((ch < ZWC('0') || ch > ZWC('9')) &&
|
||||
(ch < ZWC('a') || ch > ZWC('z')) &&
|
||||
(ch < ZWC('A') || ch > ZWC('Z'))))
|
||||
(ch < ZWC('A') || ch > ZWC('Z')))
|
||||
return 1;
|
||||
if (ch >= ZWC('A') && ch <= ZWC('Z')) /* needed in cut() */
|
||||
zmod.flags |= MOD_VIAPP;
|
||||
|
|
|
@ -10,6 +10,66 @@
|
|||
|
||||
%test
|
||||
|
||||
zletest $'yankee doodle\ebhDyy0"1P'
|
||||
0:paste register 1 to get last deletion
|
||||
>BUFFER: doodleyankee
|
||||
>CURSOR: 6
|
||||
|
||||
zletest $'yankee\eyyodoodle\edd"0p'
|
||||
0:paste register 0 to get last yank
|
||||
>BUFFER: yankee
|
||||
>yankee
|
||||
>CURSOR: 7
|
||||
|
||||
zletest $'err\eddahello\e"hddP'
|
||||
0:setting named register also sets unnamed register
|
||||
>BUFFER: hello
|
||||
>CURSOR: 0
|
||||
|
||||
zletest $'first\e"ay0ddasecond\e"Add"aP'
|
||||
0:appending to named register
|
||||
>BUFFER: firs
|
||||
>second
|
||||
>CURSOR: 0
|
||||
|
||||
zletest $'word\e"a"byy"bp'
|
||||
0:set one and then a different register
|
||||
>BUFFER: word
|
||||
>word
|
||||
>CURSOR: 5
|
||||
|
||||
zletest $'i\exaar\e0"a"_cewn\eP'
|
||||
0:set register then set black hole register
|
||||
>BUFFER: win
|
||||
>CURSOR: 1
|
||||
|
||||
zletest $'double\eyy"_"0P'
|
||||
0:reset register after selecting black hole
|
||||
>BUFFER: double
|
||||
>double
|
||||
>CURSOR: 0
|
||||
|
||||
# zsh works like vi here; in vim you get the concatenated string
|
||||
zletest $'first\e"addasecond\eddP'
|
||||
0:retrieve unnamed register after appending
|
||||
>BUFFER: second
|
||||
>CURSOR: 0
|
||||
|
||||
zletest $'Z\exayankee doodle\e"_db0"_yeP'
|
||||
0:yank and delete to black hole register
|
||||
>BUFFER: Zyankee e
|
||||
>CURSOR: 0
|
||||
|
||||
zletest $'foo\eddabar\e"_p..'
|
||||
0:paste from black hole register and repeat
|
||||
>BUFFER: bar
|
||||
>CURSOR: 2
|
||||
|
||||
zletest $'start\eFa"ac2lnew\eX"ap..'
|
||||
0:repeat paste from named register
|
||||
>BUFFER: stnwararart
|
||||
>CURSOR: 9
|
||||
|
||||
zletest $'word\euaend'
|
||||
0:undo initial change
|
||||
>BUFFER: end
|
||||
|
|
Loading…
Reference in a new issue