Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: make kill ring work in vi mode
- X-seq: zsh-workers 33576
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: Zsh workers <zsh-workers@xxxxxxx>
- Subject: Re: PATCH: make kill ring work in vi mode
- Date: Thu, 30 Oct 2014 18:54:41 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1414691683; bh=IzJWkLTphCkTAdFVFsj6sd0zjoNg/I+QqdjFQwOE5z0=; h=In-reply-to:From:References:To:Subject:Date:From:Subject; b=aFaSRGJHudv7mbNuzIR95+zuzK7RZqLnV4kv+2WtLDYYPiaeGF7L6WSAwTimsRhlNqYbaozI37bSJcHdjG15eEG22FDOt63xXp/CsANp4Bl69cm0H/bk0w+73eaYer9M0B6DGptJM6/ysXAM3Hv9ZMfywQ3DjftD6rB6FU9veAJ8xZQOrpQARyDArKy5CoPttXPX9QPqWWsu7T8j6VrXOzhwxlYv2RpXAyyty5JAwG1muLeRYcnRAgg5UGyRk1QDdBcHiXyn0WN+Pc557CbYJ/gontDe+GiDoDjE9IeAavUtGCJOU3bo+yEBO3XBJgnPxFvOHIKI/Lunk65WWSZrog==
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s2048; d=yahoo.co.uk; b=qIcMpa5IwYhCOiGWvSDi3+lebh19Mfnsup7azbEQG4ezrQHiF4NWJegqGpfVteenMWkPDceww+33GGum1gew6jqeZHiWltsHnI8fZl5dG6fb4ZQ/FcpuoqPm8Q4AdIlxDVn/0v2brd3upVL/OwXAxx+3n1yBwYz5WOjpKVlWsdfdG4aCUFuekB2TFIAA4lMr7tyn611HK6RrCuRpdLZo42N2mT413pQtr9V6mTPuD65UqJgip896L3l2CLtUHUbMvgQMap4KrbMoiYhbDq9ghe122wf+Ljl619nCxhjzJUT4VCOuHAKigawx93m/A6KPuK1kuS2iQqjeBxHVf6XEvA==;
- In-reply-to: <20141030085358.3c9f9d54@pws-pc.ntlworld.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <15607.1414626173@thecus.kiddle.eu> <20141030085358.3c9f9d54@pws-pc.ntlworld.com>
Peter wrote:
>
> Nothing here's a real problem, though if it's possible to refactor it
> more neatly that's nice to have.
Patch below refactors and adds tests. I left yank() alone which you
might question.
I think I'll ignore the undo issue until I've used it in practice
awhile. At least the current behaviour avoids the need for a
reverse-yank-pop.
Oliver
diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c
index 10bd71c..3d4a9bb 100644
--- a/Src/Zle/zle_misc.c
+++ b/Src/Zle/zle_misc.c
@@ -507,6 +507,40 @@ yank(UNUSED(char **args))
return 0;
}
+static void pastebuf(Cutbuffer buf, int mult, int after)
+{
+ int cc;
+ if (buf->flags & CUTBUFFER_LINE) {
+ if (after) {
+ 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 (after && 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)
+ DECCS();
+ }
+}
+
/**/
int
viputbefore(UNUSED(char **args))
@@ -524,24 +558,7 @@ viputbefore(UNUSED(char **args))
return 1;
kct = -1;
yankcs = zlecs;
- if (kctbuf->flags & CUTBUFFER_LINE) {
- yankb = zlecs = findbol();
- spaceinline(kctbuf->len + 1);
- ZS_memcpy(zleline + zlecs, kctbuf->buf, kctbuf->len);
- yanke = zlecs + kctbuf->len + 1;
- zleline[zlecs + kctbuf->len] = ZWC('\n');
- vifirstnonblank(zlenoargs);
- } else {
- yankb = zlecs;
- while (n--) {
- spaceinline(kctbuf->len);
- ZS_memcpy(zleline + zlecs, kctbuf->buf, kctbuf->len);
- zlecs += kctbuf->len;
- }
- yanke = zlecs;
- if (zlecs)
- DECCS();
- }
+ pastebuf(kctbuf, n, 0);
return 0;
}
@@ -562,26 +579,7 @@ viputafter(UNUSED(char **args))
return 1;
kct = -1;
yankcs = zlecs;
- if (kctbuf->flags & CUTBUFFER_LINE) {
- yankb = zlecs = findeol();
- spaceinline(kctbuf->len + 1);
- zleline[zlecs++] = ZWC('\n');
- yanke = zlecs + kctbuf->len;
- ZS_memcpy(zleline + zlecs, kctbuf->buf, kctbuf->len);
- vifirstnonblank(zlenoargs);
- } else {
- if (zlecs != findeol())
- INCCS();
- yankb = zlecs;
- while (n--) {
- spaceinline(kctbuf->len);
- ZS_memcpy(zleline + zlecs, kctbuf->buf, kctbuf->len);
- zlecs += kctbuf->len;
- }
- yanke = zlecs;
- if (zlecs)
- DECCS();
- }
+ pastebuf(kctbuf, n, 1);
return 0;
}
@@ -589,7 +587,7 @@ viputafter(UNUSED(char **args))
int
yankpop(UNUSED(char **args))
{
- int cc, kctstart = kct;
+ int kctstart = kct;
Cutbuffer buf;
if (!(lastcmd & ZLE_YANK) || !kring || !kctbuf) {
@@ -637,32 +635,7 @@ yankpop(UNUSED(char **args))
zlecs = yankb;
foredel(yanke - yankb, CUT_RAW);
zlecs = yankcs;
-
- if (buf->flags & CUTBUFFER_LINE) {
- if (lastcmd & ZLE_YANKBEFORE) {
- 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');
- } else {
- yankb = zlecs = findeol();
- spaceinline(buf->len + 1);
- zleline[zlecs++] = ZWC('\n');
- yanke = zlecs + buf->len;
- ZS_memcpy(zleline + zlecs, buf->buf, buf->len);
- }
- vifirstnonblank(zlenoargs);
- } else {
- if ((lastcmd & ZLE_YANKAFTER) && zlecs != findeol())
- INCCS();
- yankb = zlecs;
- cc = buf->len;
- spaceinline(cc);
- ZS_memcpy(zleline + zlecs, buf->buf, cc);
- zlecs += cc;
- yanke = zlecs;
- }
+ pastebuf(buf, 1, lastcmd & ZLE_YANKAFTER);
return 0;
}
diff --git a/Test/X02zlevi.ztst b/Test/X02zlevi.ztst
index 2af6f06..185980b 100644
--- a/Test/X02zlevi.ztst
+++ b/Test/X02zlevi.ztst
@@ -116,6 +116,34 @@
>BUFFER: stnwararart
>CURSOR: 9
+ zpty_run 'bindkey -a "^P" yank-pop'
+ zletest $'word\C-wline\eddiSE\eP\C-P'
+0:line based put before followed by character based yank-pop
+>BUFFER: SwordE
+>CURSOR: 4
+
+ zletest $'line\eddiword\C-w\eiSE\eP\C-P'
+0:character based put before followed by line based yank-pop
+>BUFFER: line
+>SE
+>CURSOR: 0
+
+ zletest $'one two three\C-w\C-w\C-wSE\e0p\C-P\C-P'
+0:put after cycled twice with yank-pop
+>BUFFER: SthreeE
+>CURSOR: 5
+
+ zletest $'word\C-wline\eddiSE\ehp\C-P'
+0:line based put after followed by character based yank-pop
+>BUFFER: SwordE
+>CURSOR: 5
+
+ zletest $'line\eddiword\C-w\eiSE\ehp\C-P'
+0:character based after before followed by line based yank-pop
+>BUFFER: SE
+>line
+>CURSOR: 3
+
zletest $'word\euaend'
0:undo initial change
>BUFFER: end
Messages sorted by:
Reverse Date,
Date,
Thread,
Author