From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22488 invoked by alias); 30 Nov 2014 00:10:34 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 33823 Received: (qmail 28878 invoked from network); 30 Nov 2014 00:10:32 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1417305862; bh=0z9BjqnWbPd2nUMgMKy42qiqtv7wDqWD5IpcuiE+OHE=; h=From:To:Subject:Date:From:Subject; b=hE8+2emOUTBZ7lzY8NXk3aKrUUYhZkoXfHDS+HVyDyP6kOrzk/TC4NgYEsw6VgfelUYcFIE5W0L7WY02aTKcM8SgoWkAwyjeLwFaHzT6ZiOTaPXVNi//lbok5oA1UC4SSywG5mVmIw0KhHBWETc7pyBSv2LzNj55xtBC/6aI7HaoU26cCXj2GBctQPUUKJ8s/ZEuBKt3raZxgidaSbMgDgSw24euUa6SfZsJJ+zZiwy93E3fEw//OKTiwTlBbENmUyUnOdKtB9steifSfDPVgp3i7yZQLjmVnOwnyAt+a6aXuIucLmYtwbRtuMv9BOsDCyHk5hIZQbJqFDyv4z2xhg== DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s2048; d=yahoo.co.uk; b=EiufyoYpqlt4z0tz/xvPOhkw0QkA5WEpWZsP03zkbo/qeoozZ1c1Gf2ZZvCMK9ins+Bcf2B1btnVsehZNZ/LxtrqaToUDnV47X/cDl0h/Gblr6Q8rL0+oMr2PiKgBmjJonSQ+ZBzOxdTPFnz6rr3qDjeAy/9DJsvMJUjX3uEwTVTvsT7v1O/3Q+A5t0915sRQq8Uti9JZDpeOIE1N476NzWJfhKLrJiRM+s8lYnrPuZyXLTa4Us06zuojuslKIRr0fOgkWpM5a9e0NqgI2pygH+pNwcDKtz5iOXxWgkKr0p6iB5Qo0XLFh37uAv5UVxZQvoxmzM0Uuk+guiQaDK03g==; X-Yahoo-Newman-Id: 692858.52299.bm@smtp128.mail.ir2.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: tGxqT7UVM1nu1o2nv9C87BD0WySQojJvwRPMbRk_b4r3f08 xGtYAS5wrTpsDsrmIwpvCH79di9Z5MGO0bW4TRHszeivBtKGMf0jyLsrhx0a X_3hp9Qq77168kiAxRr_g3Gu1Fc1J26ftOXUi3dINqaCA4VbtIRMekvv7aO8 ZUo.1_C9XUqo82_qNfzw5pirTCbAKnKtBDGMCr0AGf_NGUXvQWZKSQD0aqVM 14ZuXJ8BSU0IyCh4LW4DVEVaZ6vMCRMWLk4KfjTZp6y40Y2bvJZlGr_j.6l6 sqdvjB_CTUpMGiUVFEktCPLjdtL7MNY2Dikavkp9LoUXRSPAZsnKQ35DRhwy f9IuHqlebc.H5ktphBGKTFZ_oAtoXPSYT._AnVC2YxKszNew25XjktH0jVks 8DPiDpoqmipyopBHOAfDNjp._HxsjS5XNwIw4e2CtDcxX0RQeahF2382RTJs JmaEdPNaE86D7kVje.gfmHIV1f8wVQ518gGZ88Nr0Xp6pw3SFpb0tHRt13tV nEGFtJuMp944vRhCkQHQ4BCTabxsPhQ-- X-Yahoo-SMTP: opAkk_CswBAce_kJ3nIPlH80cJI- From: Oliver Kiddle To: Zsh workers Subject: PATCH: overwrite mode shouldn't replace newlines MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <13243.1417305861.1@thecus.kiddle.eu> Date: Sun, 30 Nov 2014 01:04:21 +0100 Message-ID: <13244.1417305861@thecus.kiddle.eu> In overwrite mode, either emacs style or vi-replace, on reaching the end of the line new characters should be inserted rather than the newline be replaced. There was also a bug that the numeric argument was ignored when counting characters to replace so doing 4w would replace one character with 4 'w's. Oliver diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c index a220a6b..a1dc3fa 100644 --- a/Src/Zle/zle_misc.c +++ b/Src/Zle/zle_misc.c @@ -47,13 +47,13 @@ doinsert(ZLE_STRING_T zstr, int len) iremovesuffix(c1, 0); invalidatelist(); - if (insmode) + /* In overwrite mode, don't replace newlines. */ + if (insmode || zleline[zlecs] == ZWC('\n')) spaceinline(m * len); else -#ifdef MULTIBYTE_SUPPORT { int pos = zlecs, diff, i; - +#ifdef MULTIBYTE_SUPPORT /* * Calculate the number of character positions we are * going to be using. The algorithm is that @@ -68,15 +68,18 @@ doinsert(ZLE_STRING_T zstr, int len) * useful there anyway and this doesn't cause any * particular harm. */ - for (i = 0, count = 0; i < len; i++) { + for (i = 0, count = 0; i < len * m; i++) { if (!IS_COMBINING(zstr[i])) count++; } +#else + count = len * m; +#endif /* - * Ensure we replace a complete combining character - * for each character we overwrite. + * Ensure we replace a complete combining characterfor each + * character we overwrite. Switch to inserting at first newline. */ - for (i = count; pos < zlell && i--; ) { + for (i = count; pos < zlell && zleline[pos] != ZWC('\n') && i--; ) { INCPOS(pos); } /* @@ -96,10 +99,6 @@ doinsert(ZLE_STRING_T zstr, int len) shiftchars(zlecs, diff); } } -#else - if (zlecs + m * len > zlell) - spaceinline(zlecs + m * len - zlell); -#endif while (m--) for (s = zstr, count = len; count; s++, count--) zleline[zlecs++] = *s; diff --git a/Test/X02zlevi.ztst b/Test/X02zlevi.ztst index e1ee167..5204311 100644 --- a/Test/X02zlevi.ztst +++ b/Test/X02zlevi.ztst @@ -43,6 +43,19 @@ > >CURSOR: 2 + zletest $'\eOword\eO\eraok\ejrxj.rae' +0:replace character when at end of buffer or newline +>BUFFER: ok +>wxrd +>e +>CURSOR: 9 + + zletest $'two\eOone\ehRreplace' +0:replace acts like insert at newline +>BUFFER: oreplace +>two +>CURSOR: 8 + zletest $' four\eO\C-v\tthree\eO two\eOone\e3J' 0:join lines with line count >BUFFER: one two three