Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: support numeric argument to vi-join
- X-seq: zsh-workers 33593
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: Zsh workers <zsh-workers@xxxxxxx>
- Subject: PATCH: support numeric argument to vi-join
- Date: Mon, 03 Nov 2014 00:03:41 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1414969423; bh=a9Sy5DfZIl7nYSXtze4RWd2VjMyP/toxDIYiEpaBRyc=; h=From:To:Subject:Date:From:Subject; b=G8S5mbvlkIIIkplsNdvHYjqXVjZoI46FrXptvCQSiG5IOotkxD8VqJpKp2oCrR+crgVDh/sCxsl7QK6q7J18Zlk7FMFcJYtQkvZC+LafiLexSzEWuEOxNUctTbC4lpQb/56hQInDIxQ1lieC1c6tm6UY8zdc6lv1+JFezhjGaSDZGEML7aZLalyoct67p33sCF1NH5AGfPydodJlul9CELBoCCq+GRCkR2CoTUZ86unnKkr+/gg0dxUw2PLaqqMtW/GzFUVJs6xukd0rzyac+IbmwLRJbfsQmJEKQNX1ycTYSl4kVvuw2qGOnEtTeSsviFzxgIE2o9mmX8C6GrSMOA==
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s2048; d=yahoo.co.uk; b=kKVnurW93YKsvqRCYYEIf3glnJ9x/75zFI04ofRCYJK0kmE8X7Z9+AKIWF6X+z7SAytF6FJrbsUg5/rOMyCC702iYCbPLTogLQJYXSE74TYg76mw4mB54q12S86/Uh++P2kYsQftUH+nWGor+W2siG/qDbOWSexxxCZfNBw/Vd4Q9++FYOUCYW5UcJFXgCdg2cwn1Hmn7Eq3jvlZjlQnSXKFKVVycm6wnCATgdSY6DmIdSK4hZeTmEewo/HYfslJ6/x2qeMmM3HULSsqv16RudF8qFV7OdcWLPvt54TG1NzpTlX1k7FdL5fLfb1gyevcyhRUYIyKgCJ9WpAVsFcckQ==;
- 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
This enhances vi-join to take a numeric argument. Note that, as in vi,
the number indicates how many lines to join and not how many times to
repeat the join action. So 3J does two joins combining 3 lines. Cursor
positioning is different to real vi but the same as nvi or vim.
Much of the patch is just reindentation. Tests are included.
Oliver
diff --git a/Src/Zle/zle_vi.c b/Src/Zle/zle_vi.c
index b0e696b..18c76f9 100644
--- a/Src/Zle/zle_vi.c
+++ b/Src/Zle/zle_vi.c
@@ -796,26 +796,33 @@ int
vijoin(UNUSED(char **args))
{
int x, pos;
+ int n = zmult;
startvichange(-1);
+ if (n < 1)
+ return 1;
if ((x = findeol()) == zlell)
return 1;
- zlecs = x + 1;
- pos = zlecs;
- for (; zlecs != zlell && ZC_iblank(zleline[zlecs]); INCPOS(zlecs))
- ;
- x = 1 + (zlecs - pos);
- backdel(x, CUT_RAW);
- if (zlecs) {
- int pos = zlecs;
- DECPOS(pos);
- if (ZC_iblank(zleline[pos])) {
- zlecs = pos;
- return 0;
+ while (n) {
+ zlecs = x + 1;
+ pos = zlecs;
+ for (; zlecs != zlell && ZC_iblank(zleline[zlecs]); INCPOS(zlecs))
+ ;
+ x = 1 + (zlecs - pos);
+ backdel(x, CUT_RAW);
+ if (zlecs) {
+ int pos = zlecs;
+ DECPOS(pos);
+ if (ZC_iblank(zleline[pos])) {
+ zlecs = pos;
+ return 0;
+ }
}
+ spaceinline(1);
+ zleline[zlecs] = ZWC(' ');
+ if (--n < 2 || (x = findeol()) == zlell)
+ return 0;
}
- spaceinline(1);
- zleline[zlecs] = ZWC(' ');
return 0;
}
diff --git a/Test/X02zlevi.ztst b/Test/X02zlevi.ztst
index bd3105d..f8a94ce 100644
--- a/Test/X02zlevi.ztst
+++ b/Test/X02zlevi.ztst
@@ -15,6 +15,18 @@
>BUFFER: good
>CURSOR: 4
+ zletest $' four\eO\C-v\tthree\eO two\eOone\e3J'
+0:join lines with line count
+>BUFFER: one two three
+> four
+>CURSOR: 7
+
+# like real vi, we just join as many as possible, in vim this beeps
+ zletest $'two\eOone\e3J'
+0:join more lines than possible
+>BUFFER: one two
+>CURSOR: 3
+
zletest $'one two\eyb'
0:yank left moves the cursor
>BUFFER: one two
Messages sorted by:
Reverse Date,
Date,
Thread,
Author