Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: support numeric argument to vi-join



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