zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: Zsh workers <zsh-workers@zsh.org>
Subject: Re: PATCH: fix ancient bug with empty lines
Date: Tue, 11 Nov 2014 01:15:05 +0100	[thread overview]
Message-ID: <18179.1415664905@thecus.kiddle.eu> (raw)
In-Reply-To: <15753.1415404652@thecus.kiddle.eu>

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


      reply	other threads:[~2014-11-11  0:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-07 23:57 Oliver Kiddle
2014-11-11  0:15 ` Oliver Kiddle [this message]

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=18179.1415664905@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).