Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: fix ancient bug with empty lines
- X-seq: zsh-workers 33669
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: Zsh workers <zsh-workers@xxxxxxx>
- Subject: Re: PATCH: fix ancient bug with empty lines
- Date: Tue, 11 Nov 2014 01:15:05 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1415664906; bh=3zFpCEVm+qao8h9mad4DF4GrQd/ZSTJJ8I9HBVlsesk=; h=In-reply-to:From:References:To:Subject:Date:From:Subject; b=HUF3l0lSH32lsZOgbKhhkHaWtyoDxCZuk/Duy13Hacq52tzZJvcCg/SYBOie+EkIDA0nZGswPjHXC8lF4lPsUkDrk8uIIltlWvKQjECIO6DqSzSeYm1vyvyoowYYTfZqm3HAAufCAk/XGVZRBfoZxCSdSmO6b7ubZ5cynmPYzjXK5XULZ4tvSrMJRquJCx1+o2lg9kdyC9A41Rc6YEJixyh86kgEtpaZ3gC/Dizm2VBT5O96ZVns4EGSC8JnRmvqbdiJwxkKH/NOQs/kDfnmtenMjcvGh8lI0uQrqmoX6J5XU7dezlO+ixTlDnBruP03gbB3pv72cQahDoXLxHj+Ow==
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s2048; d=yahoo.co.uk; b=gkPJQBlJSgVyMEBUHzDu4O2BKiNC6vWJzgymXDgc0b0To6QqIhjUq9nbeTuRISK6WUee7RtxoeMAQeaPx+VugiIyQVoFYJi+j0WU11Vfq9Q4s+jUDfwxp097mPPUELzIv1aUHNbkvW4PqmFEVdByB6PtvEB/VU2q6fi31f3stBJnjdKdcSQbcLZnEyCG9d7ewATnyTIztBnJFczOsl+2IAFhT/CvZTPc5ZdvPEOTe6cmqcwtdRDlvHzMRaA//nUUQIVxd0Z+YIrbYkbGZnLZpPc+r2AzK4QtHYRtW2ZiHe+dzeGg6m6gIIhNCrXdeljZoobwsyj/Io1vKo+q6XozgQ==;
- In-reply-to: <15753.1415404652@thecus.kiddle.eu>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author