zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: fix vi-indent and vi-swap-case
@ 2014-11-15  6:50 Oliver Kiddle
  2014-11-17  0:24 ` PATCH: key delays in zle tests (was fix vi-indent and vi-swap-case) Oliver Kiddle
  0 siblings, 1 reply; 3+ messages in thread
From: Oliver Kiddle @ 2014-11-15  6:50 UTC (permalink / raw)
  To: Zsh workers

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* PATCH: key delays in zle tests (was fix vi-indent and vi-swap-case)
  2014-11-15  6:50 PATCH: fix vi-indent and vi-swap-case Oliver Kiddle
@ 2014-11-17  0:24 ` Oliver Kiddle
  2014-11-18  4:09   ` Jun T.
  0 siblings, 1 reply; 3+ messages in thread
From: Oliver Kiddle @ 2014-11-17  0:24 UTC (permalink / raw)
  To: Zsh workers

I wrote:
> 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?

This allows zletest to take multiple arguments and it puts a delay
between each argument. I set KEYTIMEOUT to 1 to avoid slowing the tests
needlessly. We can always increase it if necessary.

For the delay, I've had to use read because sleep with a fraction
argument is not portable. Maybe we should make it a loadable builtin.

On the subject of KEYTIMEOUT, any thoughts on perhaps adding a separate
ESCTIMEOUT to set a different timeout specifically for an Escape (or
some other variable name)? Do you emacs mode users type Escape then Key or is
it mostly Alt/Meta? We could perhaps use different defaults for vi and
emacs mode.

Oliver

diff --git a/Test/X02zlevi.ztst b/Test/X02zlevi.ztst
index 4210a72..297fb9ae 100644
--- a/Test/X02zlevi.ztst
+++ b/Test/X02zlevi.ztst
@@ -37,6 +37,12 @@
 >3
 >CURSOR: 5
 
+  zletest $'\e' $'~aI\e' $'~o\e' \~
+0:swap case on a blank line
+>BUFFER: i
+>
+>CURSOR: 2
+
   zletest $' four\eO\C-v\tthree\eO  two\eOone\e3J'
 0:join lines with line count
 >BUFFER: one two three
diff --git a/Test/comptest b/Test/comptest
index 96072fd..654c0f1 100644
--- a/Test/comptest
+++ b/Test/comptest
@@ -36,6 +36,7 @@ comptestinit () {
 'LISTMAX=10000000
 stty 38400 columns 80 rows 24 werase undef
 TERM=vt100
+KEYTIMEOUT=1
 setopt zle
 autoload -U compinit
 compinit -u
@@ -159,9 +160,14 @@ comptest () {
 }
 
 zletest () {
-  input="$*"
-  # zpty_flush Before zletest
-  zpty -n -w zsh "$input"$'\C-X'
+  local first=0
+  for input; do
+    # sleep for $KEYTIMEOUT
+    (( first++ )) && read -t 0.011 -k 1 < /dev/null
+    # zpty_flush Before zletest
+    zpty -n -w zsh "$input"
+  done
+  zpty -n -w zsh $'\C-X'
   zpty -r -m zsh log "*<WIDGET><finish>*<PROMPT>*" || {
     print "failed to invoke finish widget."
     return 1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PATCH: key delays in zle tests (was fix vi-indent and vi-swap-case)
  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.
  0 siblings, 0 replies; 3+ messages in thread
From: Jun T. @ 2014-11-18  4:09 UTC (permalink / raw)
  To: zsh-workers

X02zlevi.ztst now fails on MacOSX and FreeBSD as follows.
Increasing the timeout in 'read -t 0.011' didn't work.

*** 1,3 ****
! BUFFER: i
! 
! CURSOR: 2
--- 1,2 ----
! BUFFER: aIo
! CURSOR: 3
Test ./X02zlevi.ztst failed: output differs from expected as shown above for:
  zletest $'\e' $'~aI\e' $'~o\e' \~
Was testing: swap case on a blank line

The following simple workaround seems to work.
If this is applied the delay by 'read -t ...' is not necessary
(on Mac, FreeBSD and Linux).

diff --git a/Test/comptest b/Test/comptest
index c67237a..f23d813 100644
--- a/Test/comptest
+++ b/Test/comptest
@@ -89,6 +89,7 @@ bindkey "^D" list-choices-with-report
 bindkey "^Z" comp-finish
 bindkey "^X" zle-finish
 bindkey -a "^X" zle-finish
+bindkey -r "\E~"
 '
 }
 




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-11-18  4:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-15  6:50 PATCH: fix vi-indent and vi-swap-case Oliver Kiddle
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.

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).