From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: Zsh workers <zsh-workers@zsh.org>
Subject: Re: PATCH: make kill ring work in vi mode
Date: Thu, 30 Oct 2014 18:54:41 +0100 [thread overview]
Message-ID: <20353.1414691681@thecus.kiddle.eu> (raw)
In-Reply-To: <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
next prev parent reply other threads:[~2014-10-30 18:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-29 23:42 Oliver Kiddle
2014-10-30 2:13 ` Bart Schaefer
2014-10-30 8:53 ` Peter Stephenson
2014-10-30 17:54 ` Oliver Kiddle [this message]
2014-10-31 11:35 ` Vin Shelton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20353.1414691681@thecus.kiddle.eu \
--to=okiddle@yahoo.co.uk \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).