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

PATCH: fix ancient bug with empty lines



I wrote:
> There's an existing old bug with blank lines: dd on a blank line doesn't
> work. It works in 3.0.8 but not in 4.2.1.

It was broken early in the 3.1 branch, definitely before 1997.

The problem is that virangeflag was being reset. This will have been
done so some of the up-line-or-history style commands can tell whether
they're being used from vi operators. Unfortunately this was done too
early losing values being passed back. For empty lines, the value of 2
indicates that getvirange should accept the lack of movement because the
empty line is being selected. Furthermore, a value of -1 is used for
vi-match-bracket to indiciate that a cursor adjustment is required. This
was also broken: a backward movement with % was missing one character.

It is still broken for yy. This is a separate problem: we want to cut
zero bytes but set CUTBUFFER_LINE. I'm not sure how to fix that exactly.

Oliver

diff --git a/Src/Zle/zle_vi.c b/Src/Zle/zle_vi.c
index d74b40d..a60caa2 100644
--- a/Src/Zle/zle_vi.c
+++ b/Src/Zle/zle_vi.c
@@ -202,7 +202,6 @@ getvirange(int wf)
 	    zmult = mult1 * zmod.tmult;
     } while(prefixflag && !ret);
     wordflag = 0;
-    virangeflag = 0;
 
     /* It is an error to use a non-movement command to delimit the *
      * range.  We here reject the case where the command modified  *
@@ -222,14 +221,9 @@ getvirange(int wf)
     /* vi-match-bracket changes the value of virangeflag when *
      * moving to the opening bracket, meaning that we need to *
      * change the *starting* position.                        */
-    if(virangeflag == -1)
-    {
-	int origcs = zlecs;
-	zlecs = pos;
-	INCCS();
-	pos = zlecs;
-	zlecs = origcs;
-    }
+    if (virangeflag == -1)
+	INCPOS(pos);
+    virangeflag = 0;
 
     /* Get the range the right way round.  zlecs is placed at the *
      * start of the range, and pos (the return value of this   *
diff --git a/Test/X02zlevi.ztst b/Test/X02zlevi.ztst
index 561a5fd..7e5385b 100644
--- a/Test/X02zlevi.ztst
+++ b/Test/X02zlevi.ztst
@@ -15,6 +15,21 @@
 >BUFFER: good
 >CURSOR: 4
 
+  zletest $'{ ({[}]) }\e0c%chg'
+0:change forward to matching bracket
+>BUFFER: chg
+>CURSOR: 3
+
+  zletest $'s( match )\ed%'
+0:delete backwards to matching bracket
+>BUFFER: s
+>CURSOR: 0
+
+  zletest $'one\eo\edd'
+0:delete empty line
+>BUFFER: one
+>CURSOR: 0
+
   zletest $' four\eO\C-v\tthree\eO  two\eOone\e3J'
 0:join lines with line count
 >BUFFER: one two three



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