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

PATCH: fix vi-indent and vi-swap-case



vi-swap-case was failing to account for blank lines and moving the
cursor backwards to the previous line due to the code that is there to
adjust the cursor back to the last position on the line.

vi-indent was failing to indent the final line if it contained 2 or
fewer characters. This was effectively two separate off-by-one errors
accumulating. Furthermore, it shouldn't put indentation on blank lines.

There's still a further bug that I've not been able to track down. After
vi-indent ZLE is sometimes scrolling up a line needlessly. To reproduce
do the following (patch is not needed for this).

[Escape]o123[Escape]>k

I'm guessing this is either caused somehow by spaceinline or simply just
in zrefresh. I'm fairly sure I've seen it happen in other ways.

It'd be nice if it could be configured to use, e.g a couple of spaces,
instead of tabs for indentation.

No test for vi-swap-case because _bash_completions is getting in
the way to do username completion on \e~. Any idea how we can get
zletest to sleep for a $KEYTIMEOUT delay?

\e~ never bothers me interactively because ~ requires a shift but \e/
is a real nuisance (if you don't remove the binding). I've always
found _history_complete_word to be weird compared to what you get with
_generic anyway.

There's also a fix to zletest: it was losing blank lines.

Oliver

diff --git a/Src/Zle/zle_vi.c b/Src/Zle/zle_vi.c
index a60caa2..68b1c92 100644
--- a/Src/Zle/zle_vi.c
+++ b/Src/Zle/zle_vi.c
@@ -700,10 +700,14 @@ viindent(UNUSED(char **args))
     }
     oldcs = zlecs;
     /* add a tab to the beginning of each line within range */
-    while (zlecs < c2) {
-	spaceinline(1);
-	zleline[zlecs] = '\t';
-	zlecs = findeol() + 1;
+    while (zlecs <= c2 + 1) {
+	if (zleline[zlecs] == '\n') { /* leave blank lines alone */
+	    ++zlecs;
+	} else {
+	    spaceinline(1);
+	    zleline[zlecs] = '\t';
+	    zlecs = findeol() + 1;
+	}
     }
     /* go back to the first line of the range */
     zlecs = oldcs;
@@ -830,6 +834,8 @@ viswapcase(UNUSED(char **args))
     if (n < 1)
 	return 1;
     eol = findeol();
+    if (zlecs == eol)
+	return 1;
     while (zlecs < eol && n--) {
 	if (ZC_ilower(zleline[zlecs]))
 	    zleline[zlecs] = ZC_toupper(zleline[zlecs]);
diff --git a/Test/X02zlevi.ztst b/Test/X02zlevi.ztst
index 4b9c4d9..4210a72 100644
--- a/Test/X02zlevi.ztst
+++ b/Test/X02zlevi.ztst
@@ -49,6 +49,24 @@
 >BUFFER: one two
 >CURSOR: 3
 
+  zletest $'fi\eO\eOif\e2>j'
+0:don't indent blank lines
+>BUFFER: 	if
+>
+>	fi
+>CURSOR: 1
+
+  zletest $'\C-v\ti\e>>'
+0:additional indentation
+>BUFFER: 		i
+>CURSOR: 2
+
+  zletest $'one\eox\e>k'
+0:indent with one character on final line
+>BUFFER: 	one
+>	x
+>CURSOR: 1
+
   zletest $'one two\eyb'
 0:yank left moves the cursor
 >BUFFER: one two
@@ -104,12 +122,14 @@
   zletest $'err\eddahello\e"hddP'
 0:setting named register also sets unnamed register
 >BUFFER: hello
+>
 >CURSOR: 0
 
   zletest $'first\e"ay0ddasecond\e"Add"aP'
 0:appending to named register
 >BUFFER: firs
 >second
+>
 >CURSOR: 0
 
   zletest $'word\e"a"byy"bp'
@@ -133,6 +153,7 @@
   zletest $'first\e"addasecond\eddP'
 0:retrieve unnamed register after appending
 >BUFFER: second
+>
 >CURSOR: 0
 
   zletest $'Z\exayankee doodle\e"_db0"_yeP'
diff --git a/Test/comptest b/Test/comptest
index b6256cc..96072fd 100644
--- a/Test/comptest
+++ b/Test/comptest
@@ -167,5 +167,5 @@ zletest () {
     return 1
   }
   # zpty_flush After zletest
-  print -lr "${(@)${(ps:\r\n:)log##*<WIDGET><finish>}[1,-2]}"
+  print -lr "${(@)${(@ps:\r\n:)log##*<WIDGET><finish>}[2,-2]}"
 }



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