zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: Zsh workers <zsh-workers@zsh.org>
Subject: PATCH: fix vi-indent and vi-swap-case
Date: Sat, 15 Nov 2014 07:50:52 +0100	[thread overview]
Message-ID: <4968.1416034252@thecus.kiddle.eu> (raw)

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]}"
 }


             reply	other threads:[~2014-11-15  6:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-15  6:50 Oliver Kiddle [this message]
2014-11-17  0:24 ` PATCH: key delays in zle tests (was fix vi-indent and vi-swap-case) Oliver Kiddle
2014-11-18  4:09   ` Jun T.

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4968.1416034252@thecus.kiddle.eu \
    --to=okiddle@yahoo.co.uk \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).