zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: support numeric argument to vi-join
@ 2014-11-02 23:03 Oliver Kiddle
  0 siblings, 0 replies; only message in thread
From: Oliver Kiddle @ 2014-11-02 23:03 UTC (permalink / raw)
  To: Zsh workers

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-11-02 23:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-02 23:03 PATCH: support numeric argument to vi-join Oliver Kiddle

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).