From: Han Pingtian <hanpt@linux.vnet.ibm.com>
To: zsh-workers@zsh.org
Subject: [PATCH] enable number argument for transpose-words
Date: Mon, 1 Aug 2016 18:32:12 +0800 [thread overview]
Message-ID: <20160801103212.GA24067@localhost.localdomain> (raw)
Looks like number argument doesn't work for transpose-words widget: if
the number is even, there is no words transposed; if the number is odd,
the behavior is the same of no number argument given.
With this patch, current word will be transposed with the preious nth
word if number argument n given.
Signed-off-by: Han Pingtian <hanpt@linux.vnet.ibm.com>
---
Src/Zle/zle_word.c | 90 +++++++++++++++++++++++++++++++-----------------------
1 file changed, 51 insertions(+), 39 deletions(-)
diff --git a/Src/Zle/zle_word.c b/Src/Zle/zle_word.c
index 3c1f26c..2a15171 100644
--- a/Src/Zle/zle_word.c
+++ b/Src/Zle/zle_word.c
@@ -678,46 +678,54 @@ killword(char **args)
int
transposewords(UNUSED(char **args))
{
- int p1, p2, p3, p4, len, x = zlecs, pos;
+ int p1, p2, p3, p4, pt, len, x = zlecs, pos;
ZLE_STRING_T temp, pp;
int n = zmult;
int neg = n < 0, ocs = zlecs;
if (neg)
n = -n;
- while (n--) {
- while (x != zlell && zleline[x] != ZWC('\n') && !ZC_iword(zleline[x]))
- INCPOS(x);
- if (x == zlell || zleline[x] == ZWC('\n')) {
- x = zlecs;
- while (x) {
- if (ZC_iword(zleline[x]))
- break;
- pos = x;
- DECPOS(pos);
- if (zleline[pos] == ZWC('\n'))
- break;
- x = pos;
- }
- if (!x)
- return 1;
+
+ while (x != zlell && zleline[x] != ZWC('\n') && !ZC_iword(zleline[x]))
+ INCPOS(x);
+
+ if (x == zlell || zleline[x] == ZWC('\n')) {
+ x = zlecs;
+ while (x) {
+ if (ZC_iword(zleline[x]))
+ break;
pos = x;
DECPOS(pos);
if (zleline[pos] == ZWC('\n'))
- return 1;
- }
- for (p4 = x; p4 != zlell && ZC_iword(zleline[p4]); INCPOS(p4))
- ;
- for (p3 = p4; p3; ) {
- pos = p3;
- DECPOS(pos);
- if (!ZC_iword(zleline[pos]))
break;
- p3 = pos;
+ x = pos;
}
- if (!p3)
+ if (!x)
return 1;
- for (p2 = p3; p2; ) {
+ pos = x;
+ DECPOS(pos);
+ if (zleline[pos] == ZWC('\n'))
+ return 1;
+ }
+
+ for (p4 = x; p4 != zlell && ZC_iword(zleline[p4]); INCPOS(p4))
+ ;
+
+ for (p3 = p4; p3; ) {
+ pos = p3;
+ DECPOS(pos);
+ if (!ZC_iword(zleline[pos]))
+ break;
+ p3 = pos;
+ }
+
+ if (!p3)
+ return 1;
+
+ pt = p3;
+
+ while (n--) {
+ for (p2 = pt; p2; ) {
pos = p2;
DECPOS(pos);
if (ZC_iword(zleline[pos]))
@@ -733,20 +741,24 @@ transposewords(UNUSED(char **args))
break;
p1 = pos;
}
- pp = temp = (ZLE_STRING_T)zhalloc((p4 - p1)*ZLE_CHAR_SIZE);
- len = p4 - p3;
- ZS_memcpy(pp, zleline + p3, len);
- pp += len;
- len = p3 - p2;
- ZS_memcpy(pp, zleline + p2, len);
- pp += len;
- ZS_memcpy(pp, zleline + p1, p2 - p1);
+ pt = p1;
+ }
- ZS_memcpy(zleline + p1, temp, p4 - p1);
+ pp = temp = (ZLE_STRING_T)zhalloc((p4 - p1)*ZLE_CHAR_SIZE);
+ len = p4 - p3;
+ ZS_memcpy(pp, zleline + p3, len);
+ pp += len;
+ len = p3 - p2;
+ ZS_memcpy(pp, zleline + p2, len);
+ pp += len;
+ ZS_memcpy(pp, zleline + p1, p2 - p1);
+
+ ZS_memcpy(zleline + p1, temp, p4 - p1);
- zlecs = p4;
- }
if (neg)
zlecs = ocs;
+ else
+ zlecs = p4;
+
return 0;
}
--
2.5.5
next reply other threads:[~2016-08-01 11:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-01 10:32 Han Pingtian [this message]
2016-08-12 2:54 ` Han Pingtian
2016-08-12 9:29 ` Peter Stephenson
2016-08-12 10:25 ` Kamil Dudka
2016-08-12 10:41 ` Peter Stephenson
2016-08-12 13:10 ` Kamil Dudka
2016-08-15 2:22 ` Han Pingtian
2016-08-15 8:39 ` Peter Stephenson
2016-08-15 9:01 ` Peter Stephenson
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=20160801103212.GA24067@localhost.localdomain \
--to=hanpt@linux.vnet.ibm.com \
--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).