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

PATCH: vi-mode word movement improvements to newline handling



This patch affects how newlines are handled in the vi-mode word movement
widgets. There were one or two cases that were clear bugs (e.g. b would stop
at the end of the last word on a preceding lines). Mostly, this is just
improving compatibility with vi. There are still subtle differences such
as for a line containing just spaces but at that level, you'll also find
differences between vi/vim/nvi.

Oliver

diff --git a/Src/Zle/zle_word.c b/Src/Zle/zle_word.c
index cb5e5db..2e6d75e 100644
--- a/Src/Zle/zle_word.c
+++ b/Src/Zle/zle_word.c
@@ -80,16 +80,21 @@ viforwardword(char **args)
 	return ret;
     }
     while (n--) {
+	int nl;
 	if (Z_vialnum(zleline[zlecs]))
 	    while (zlecs != zlell && Z_vialnum(zleline[zlecs]))
 		INCCS();
 	else
-	    while (zlecs != zlell && !Z_vialnum(zleline[zlecs]) && !ZC_iblank(zleline[zlecs]))
+	    while (zlecs != zlell && !Z_vialnum(zleline[zlecs]) &&
+		    !ZC_inblank(zleline[zlecs]))
 		INCCS();
 	if (wordflag && !n)
 	    return 0;
-	while (zlecs != zlell && ZC_inblank(zleline[zlecs]))
+	nl = (zleline[zlecs] == ZWC('\n'));
+	while (zlecs != zlell && nl < 2 && ZC_inblank(zleline[zlecs])) {
 	    INCCS();
+	    nl += (zleline[zlecs] == ZWC('\n'));
+	}
     }
     return 0;
 }
@@ -108,12 +113,16 @@ viforwardblankword(char **args)
 	return ret;
     }
     while (n--) {
-	while (zlecs != zlell && !ZC_iblank(zleline[zlecs]))
+	int nl;
+	while (zlecs != zlell && !ZC_inblank(zleline[zlecs]))
 	    INCCS();
 	if (wordflag && !n)
 	    return 0;
-	while (zlecs != zlell && ZC_iblank(zleline[zlecs]))
+	nl = (zleline[zlecs] == ZWC('\n'));
+	while (zlecs != zlell && nl < 2 && ZC_inblank(zleline[zlecs])) {
 	    INCCS();
+	    nl += (zleline[zlecs] == ZWC('\n'));
+	}
     }
     return 0;
 }
@@ -159,14 +168,14 @@ viforwardblankwordend(UNUSED(char **args))
 	while (zlecs != zlell) {
 	    int pos = zlecs;
 	    INCPOS(pos);
-	    if (!ZC_iblank(zleline[pos]))
+	    if (!ZC_inblank(zleline[pos]))
 		break;
 	    zlecs = pos;
 	}
 	while (zlecs != zlell) {
 	    int pos = zlecs;
 	    INCPOS(pos);
-	    if (ZC_iblank(zleline[pos]))
+	    if (ZC_inblank(zleline[pos]))
 		break;
 	    zlecs = pos;
 	}
@@ -216,7 +225,7 @@ viforwardwordend(char **args)
 		    if (zlecs == zlell)
 			break;
 		    INCPOS(pos);
-		    if (Z_vialnum(zleline[pos]) || ZC_iblank(zleline[pos]))
+		    if (Z_vialnum(zleline[pos]) || ZC_inblank(zleline[pos]))
 			break;
 		}
 	    }
@@ -273,16 +282,19 @@ vibackwardword(char **args)
 	return ret;
     }
     while (n--) {
+	int nl = 0;
 	while (zlecs) {
-	    int pos = zlecs;
-	    DECPOS(pos);
-	    if (!ZC_iblank(zleline[pos]))
+	    DECCS();
+	    if (!ZC_inblank(zleline[zlecs]))
 		break;
-	    zlecs = pos;
+	    nl += (zleline[zlecs] == ZWC('\n'));
+	    if (nl == 2) {
+		INCCS();
+		break;
+	    }
 	}
 	if (zlecs) {
 	    int pos = zlecs;
-	    DECPOS(pos);
 	    if (Z_vialnum(zleline[pos])) {
 		for (;;) {
 		    zlecs = pos;
@@ -298,7 +310,7 @@ vibackwardword(char **args)
 		    if (zlecs == 0)
 			break;
 		    DECPOS(pos);
-		    if (Z_vialnum(zleline[pos]) || ZC_iblank(zleline[pos]))
+		    if (Z_vialnum(zleline[pos]) || ZC_inblank(zleline[pos]))
 			break;
 		}
 	    }
@@ -321,17 +333,20 @@ vibackwardblankword(char **args)
 	return ret;
     }
     while (n--) {
+	int nl = 0;
 	while (zlecs) {
 	    int pos = zlecs;
 	    DECPOS(pos);
-	    if (!ZC_iblank(zleline[pos]))
+	    if (!ZC_inblank(zleline[pos]))
 		break;
+	    nl += (zleline[pos] == ZWC('\n'));
+	    if (nl == 2) break;
 	    zlecs = pos;
 	}
 	while (zlecs) {
 	    int pos = zlecs;
 	    DECPOS(pos);
-	    if (ZC_iblank(zleline[pos]))
+	    if (ZC_inblank(zleline[pos]))
 		break;
 	    zlecs = pos;
 	}
@@ -356,7 +371,7 @@ vibackwardwordend(char **args)
 	int start = 0;
 	if (Z_vialnum(zleline[zlecs]))
 	    start = 1;
-	else if (!ZC_iblank(zleline[zlecs]))
+	else if (!ZC_inblank(zleline[zlecs]))
 	    start = 2;
 	DECCS();
 	while (zlecs) {
@@ -387,9 +402,9 @@ vibackwardblankwordend(char **args)
 	return ret;
     }
     while (n--) {
-	while (zlecs && !ZC_iblank(zleline[zlecs]))
+	while (zlecs && !ZC_inblank(zleline[zlecs]))
 	    DECCS();
-	while (zlecs && ZC_iblank(zleline[zlecs]))
+	while (zlecs && ZC_inblank(zleline[zlecs]))
 	    DECCS();
     }
     return 0;
diff --git a/Test/X02zlevi.ztst b/Test/X02zlevi.ztst
index 6ca047d..14bc02e 100644
--- a/Test/X02zlevi.ztst
+++ b/Test/X02zlevi.ztst
@@ -414,6 +414,94 @@
 >BUFFER: One tWO three
 >CURSOR: 4
 
+  zletest $' --ww  ww--\eo\eoww\eo\eo--\eo\eo  ww\e' bi{a,b,c,d,e,f,g,h,i,j,k}$'\e'
+0:backward word
+>BUFFER: k j--iww  hwwg--
+>f
+>eww
+>d
+>c--
+>b
+>  aww
+>CURSOR: 0
+
+  zletest $' --ww  ww--\eo\eoww\eo\eo--\eo\eo  ww\e' Bi{a,b,c,d,e,f,g,h,i}$'\e'
+0:backword blank word
+>BUFFER: i h--ww  gww--
+>f
+>eww
+>d
+>c--
+>b
+>  aww
+>CURSOR: 0
+
+  zletest $' --ww  ww--\eo\eoww\eo\eo--\eo\eo  ww\e' gei{a,=,b,c,=,d,e,=,f}$'\e'
+0:backward word end
+>BUFFER: f -=-wew  wdw-=-
+>c
+>wbw
+>
+>-=-
+>a
+>  ww
+>CURSOR: 0
+
+  zletest $' --ww  ww--\eo\eoww\eo\eo--\eo\eo  ww\e' gEi{=,b,=,d,e}$'\e'
+0:backward blank word end
+>BUFFER: e --wdw  ww-=-
+>
+>wbw
+>
+>-=-
+>
+>  ww
+>CURSOR: 0
+
+  zletest $'  ww\eO\eO--\eO\eOww\eO\eO --ww  ww--\e0' wi{=,a,b,=,c,d,e,=,f,g}$'\e'
+0:forward word
+>BUFFER:  =--aww  bww=--
+>c
+>dww
+>e
+>=--
+>f
+>  gww
+>CURSOR: 32
+
+  zletest $'  ww\eO\eO--\eO\eOww\eO\eO --ww  ww--\e0' Wi{=,a,b,c,d,=,e,f}$'\e'
+0:forward blank word
+>BUFFER:  =--ww  aww--
+>b
+>cww
+>d
+>=--
+>e
+>  fww
+>CURSOR: 30
+
+  zletest $'  ww\eO\eO--\eO\eOww\eO\eO --ww  ww--\e0' ea{a,b,c,d,e,f,g}$'\e'
+0:forward word end
+>BUFFER:  --awwb  wwc--d
+>
+>wwe
+>
+>--f
+>
+>  wwg
+>CURSOR: 31
+
+  zletest $'  ww\eO\eO--\eO\eOww\eO\eO --ww  ww--\e0' Ea{a,b,c,d,e}$'\e'
+0:forward blank word end
+>BUFFER:  --wwa  ww--b
+>
+>wwc
+>
+>--d
+>
+>  wwe
+>CURSOR: 29
+
   zletest $'    ----word    ----    word    word----    ----\e42|daw30|daw22|daw14|daw2|daw'
 0:delete all word on blanks
 >BUFFER: word



Messages sorted by: Reverse Date, Date, Thread, Author