Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: fix vi-indent and vi-swap-case
- X-seq: zsh-workers 33695
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: Zsh workers <zsh-workers@xxxxxxx>
- Subject: PATCH: fix vi-indent and vi-swap-case
- Date: Sat, 15 Nov 2014 07:50:52 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1416034254; bh=pHdk9ssBvyPC+0bYBGPG30qX4hg8rl1qTsmff+3lJrI=; h=From:To:Subject:Date:From:Subject; b=qE2uT0BpdYmAiNKdkBdH5FRlJkfr021IvSD48OJ9wMnW8wAoAbfvvG6BkWDhKjJESM8sRa9ccePFv5RpJnQ+XzDAcuo1502HrN3cb1YQw7M+8Dsa6Udwn+OAfnMqDEFpmH4l0LG+C4uZv00t2pfqVYTvIYl1I8ZOEMtJPNl7i5Qzm3LnnhjCveca7q26aFd9bVWFyGzmWVcAiTUCjOca2aBoGNGWPz/hSljC76+aavw8bpiwHpIXi91RIOggBG6gxvRRSS9eLvt2Vz2leIM3L82ya2eDfSzEd01f5k01qAuKS8WmGe6DKSUWouQz17bUZf7EKhqz0INTtz0lZX5lbQ==
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s2048; d=yahoo.co.uk; b=eTBBTphY+QwkGBXvAnujqE8gjASbAJR9Y1I1CUiNQxZxc5O3kW9XAZ2eoQeuL2TfYCqH1rjw7G5/9ShOqcx423HkF3/4OAqu1UOoLMoJwzJXyhPpEoqh/8n6odqpD141EPKLOq6zqxNikT8flnMAS//qQlCq5gkuEsNrAKtKphqymDaS353M4fwxXtLEMZS73jWBt0BSseqGOVUNGaJz0DOdFfsC8N8sX7kuA3N85szF33lb53VL4XVaEcOlQ4XqfM73MKLbDB2FuYEyEAA2UdVg7eBhFkhbDtrCrQIyCoBkiEUhARyqBW6hfk0hHDXfyV1Dv4SJFzMhv82P9G/0sw==;
- 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
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