zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: fix ancient bug with empty lines
@ 2014-11-07 23:57 Oliver Kiddle
  2014-11-11  0:15 ` Oliver Kiddle
  0 siblings, 1 reply; 2+ messages in thread
From: Oliver Kiddle @ 2014-11-07 23:57 UTC (permalink / raw)
  To: Zsh workers

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


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

* Re: PATCH: fix ancient bug with empty lines
  2014-11-07 23:57 PATCH: fix ancient bug with empty lines Oliver Kiddle
@ 2014-11-11  0:15 ` Oliver Kiddle
  0 siblings, 0 replies; 2+ messages in thread
From: Oliver Kiddle @ 2014-11-11  0:15 UTC (permalink / raw)
  To: Zsh workers

On 8 Nov, I wrote:
> 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.

This did work in 3.0 too, though I'll admit it's not entirely useful.
It stems in part from 13767 which tries to avoid doing an alloc of
0 bytes. Are there any thoughts on this patch which makes it allocate 1
byte. zalloc does much the same.

We still separately block attempts to do yy, dd, cc etc on a completely
empty buffer. I'm not inclined to do anything about that.

Oliver


diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c
index 03a2bdc..f56063e 100644
--- a/Src/Zle/zle_utils.c
+++ b/Src/Zle/zle_utils.c
@@ -916,7 +916,7 @@ cut(int i, int ct, int flags)
 void
 cuttext(ZLE_STRING_T line, int ct, int flags)
 {
-    if (!ct || zmod.flags & MOD_NULL)
+    if (!(ct || vilinerange) ||  zmod.flags & MOD_NULL)
 	return;
 
     UNMETACHECK();
@@ -989,8 +989,9 @@ cuttext(ZLE_STRING_T line, int ct, int flags)
 	cutbuf.buf = s;
 	cutbuf.len += ct;
     } else {
+	/* don't alloc 0 bytes; length 0 occurs for blank lines in vi mode */
 	cutbuf.buf = realloc((char *)cutbuf.buf,
-			     (cutbuf.len + ct) * ZLE_CHAR_SIZE);
+			     (cutbuf.len + (ct ? ct : 1)) * ZLE_CHAR_SIZE);
 	ZS_memcpy(cutbuf.buf + cutbuf.len, line, ct);
 	cutbuf.len += ct;
     }
diff --git a/Test/X02zlevi.ztst b/Test/X02zlevi.ztst
index 7e5385b..4b9c4d9 100644
--- a/Test/X02zlevi.ztst
+++ b/Test/X02zlevi.ztst
@@ -30,6 +30,13 @@
 >BUFFER: one
 >CURSOR: 0
 
+  zletest $'1\eo\eyya2\epa3'
+0:yank and paste blank line
+>BUFFER: 1
+>2
+>3
+>CURSOR: 5
+
   zletest $' four\eO\C-v\tthree\eO  two\eOone\e3J'
 0:join lines with line count
 >BUFFER: one two three


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

end of thread, other threads:[~2014-11-11  0:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-07 23:57 PATCH: fix ancient bug with empty lines Oliver Kiddle
2014-11-11  0:15 ` Oliver Kiddle

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