From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15357 invoked by alias); 23 Oct 2014 19:32:09 -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: 33518 Received: (qmail 6109 invoked from network); 23 Oct 2014 19:32:05 -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=s1024; t=1414092350; bh=ETaTFp+6YZMqMmR6mKtQ4BHHwi8y6v9KdY2AGbGIKtg=; h=X-Yahoo-Newman-Id:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:In-reply-to:From:References:To:Subject:MIME-Version:Content-Type:Content-ID:Date:Message-ID; b=eqLhjtruNNE3nj4Wos5gGCDsNWCmA+LSeUfkBbhTVr2KsjfkEeNFteO2jB1iztncJo/rj5ggusc0bkWzPg7dp1E1ROhUu7VhmJXuOSD6/KRSi2aLWSG7RmTFvc7x8PWnl9AS9m2Mb+oqPjDyQg168Llt7krJJMyzfXBcXUW0uy4= X-Yahoo-Newman-Id: 381999.4999.bm@smtp102.mail.ir2.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: HzfECW8VM1n4XrdLZryqk60R.0V1P4IQnxa5yHgK08ZARR. TgEdAKFoxg23ZjVi3phijLvm4aANuCnL6rJ_6jx.H3laLjn.rCThpw.eUhcZ Jp2t33LbgRVoSi1eslBA6C6GzayN2IPv63zxUeVSKCK9no9TtHYoerHZBsnr F2ll6aQVrCu8whLWv69xOqxmcIYihpTLCXHD5CC7BAgD2Xt4fJX2goZBGMxi pK.czpSdX9wHXgH_KeVLl_euRVxS3TeZ9g8JXqjz44izgMbBDJ99CWG_AyUe 8bvR3GvqmGWoCmh33R2TktBemY9ftTX1K1shr2rmbGaC4FL93LNzJjpC.CxM O7GXISnQr8YuNghlsLVobmO6QHDAzh.9es27iHdGpRFmwW7j8K5H8S.D8kVK b8fNYmOStGHFOink3.rw18SYxvgrHQU4ND2o2gEXG3sUGFsmcc_MCm3JK4bd 7VSHFhpNdnOJzOKy8.D7WuZQZ60Puc.LxaWRHgMydVgL7uvx0w13flkSCO2. ATJUwzPr7XL5v49fQ2Y.JNW62xd2KIg-- X-Yahoo-SMTP: opAkk_CswBAce_kJ3nIPlH80cJI- In-reply-to: <28859.1414015603@thecus.kiddle.eu> From: Oliver Kiddle References: <25197.1413973482@thecus.kiddle.eu> <28859.1414015603@thecus.kiddle.eu> To: zsh-workers@zsh.org Subject: Re: PATCH: Re: bug report: vi mode yank should yank to 0 register MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2085.1414092349.1@thecus.kiddle.eu> Date: Thu, 23 Oct 2014 21:25:49 +0200 Message-ID: <2087.1414092349@thecus.kiddle.eu> Of the other vim registers "_ (the black hole register) is both useful and meaningful in zsh so this adds that. I've also changed vi-set-buffer so that when invoked from a zle widget, you can pass it the name of a buffer to use so you can now use the following before other commands in order to leave the cut buffer untouched. zle vi-set-buffer _ This also adds documentation and tests. Oliver diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index 98f3802..881e56b 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -2180,19 +2180,29 @@ command. tt(run-help) is normally aliased to tt(man). tindex(vi-set-buffer) item(tt(vi-set-buffer) (unbound) (") (unbound))( Specify a buffer to be used in the following command. -There are 35 buffers that can be specified: -the 26 `named' buffers tt("a) to tt("z) -and the nine `queued' buffers tt("1) to tt("9). The named buffers can also -be specified as tt("A) to tt("Z). - -When a buffer is specified for a cut command, the text being cut replaces -the previous contents of the specified buffer. If a named buffer -is specified using a capital, the newly cut text is appended to the buffer -instead of overwriting it. - -If no buffer is specified for a cut command, tt("1) is used, and the -contents of tt("1) to tt("8) are each shifted along one buffer; the contents of -tt("9) is lost. +There are 37 buffers that can be specified: +the 26 `named' buffers tt("a) to tt("z), the `yank' buffer tt("0), +the nine `queued' buffers tt("1) to tt("9) and the `black hole' buffer +tt("_). The named buffers can also be specified as tt("A) to tt("Z). + +When a buffer is specified for a cut, change or yank command, the text +concerned replaces the previous contents of the specified buffer. If +a named buffer is specified using a capital, the newly cut text is +appended to the buffer instead of overwriting it. When using the tt("_) +buffer, nothing happens. This can be useful for deleting text without +affecting the normal registers. + +If no buffer is specified for a cut or change command, tt("1) is used, and +the contents of tt("1) to tt("8) are each shifted along one buffer; +the contents of tt("9) is lost. If no buffer is specified for a yank +command, tt("0") is used. Finally, a paste command without a specified +buffer will paste the text from the most recent command regardless of any +buffer that might have been used with that command. + +When called from a widget function by the tt(zle) command, the buffer +can optionally be specified with an argument. For example, + +example(zle vi-set-buffer A) ) tindex(vi-set-mark) item(tt(vi-set-mark) (unbound) (m) (unbound))( diff --git a/Src/Zle/zle.h b/Src/Zle/zle.h index 860c821..dd6cdcc 100644 --- a/Src/Zle/zle.h +++ b/Src/Zle/zle.h @@ -240,6 +240,7 @@ struct modifier { #define MOD_VIBUF (1<<2) /* a vi cut buffer has been selected */ #define MOD_VIAPP (1<<3) /* appending to the vi cut buffer */ #define MOD_NEG (1<<4) /* last command was negate argument */ +#define MOD_NULL (1<<5) /* throw away text for the vi cut buffer */ /* current modifier status */ diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c index f69bc77..46d5373 100644 --- a/Src/Zle/zle_utils.c +++ b/Src/Zle/zle_utils.c @@ -914,7 +914,7 @@ cut(int i, int ct, int flags) void cuttext(ZLE_STRING_T line, int ct, int flags) { - if (!ct) + if (!ct || zmod.flags & MOD_NULL) return; UNMETACHECK(); diff --git a/Src/Zle/zle_vi.c b/Src/Zle/zle_vi.c index 2555c6a..20cece0 100644 --- a/Src/Zle/zle_vi.c +++ b/Src/Zle/zle_vi.c @@ -782,7 +782,7 @@ viputbefore(UNUSED(char **args)) int n = zmult; startvichange(-1); - if (n < 0) + if (n < 0 || zmod.flags & MOD_NULL) return 1; if (zmod.flags & MOD_VIBUF) buf = &vibuf[zmod.vibuf]; @@ -814,7 +814,7 @@ viputafter(UNUSED(char **args)) int n = zmult; startvichange(-1); - if (n < 0) + if (n < 0 || zmod.flags & MOD_NULL) return 1; if (zmod.flags & MOD_VIBUF) buf = &vibuf[zmod.vibuf]; @@ -905,14 +905,26 @@ vicapslockpanic(UNUSED(char **args)) /**/ int -visetbuffer(UNUSED(char **args)) +visetbuffer(char **args) { ZLE_INT_T ch; - if ((zmod.flags & MOD_VIBUF) || - (((ch = getfullchar(0)) < ZWC('0') || ch > ZWC('9')) && + if (*args) { + ch = **args; + if (args[1] || (ch && (*args)[1])) + return 1; + } else { + ch = getfullchar(0); + } + if (ch == ZWC('_')) { + zmod.flags |= MOD_NULL; + prefixflag = 1; + return 0; + } else + zmod.flags &= ~MOD_NULL; + if ((ch < ZWC('0') || ch > ZWC('9')) && (ch < ZWC('a') || ch > ZWC('z')) && - (ch < ZWC('A') || ch > ZWC('Z')))) + (ch < ZWC('A') || ch > ZWC('Z'))) return 1; if (ch >= ZWC('A') && ch <= ZWC('Z')) /* needed in cut() */ zmod.flags |= MOD_VIAPP; diff --git a/Test/X02zlevi.ztst b/Test/X02zlevi.ztst index 19188df..507107e 100644 --- a/Test/X02zlevi.ztst +++ b/Test/X02zlevi.ztst @@ -10,6 +10,66 @@ %test + zletest $'yankee doodle\ebhDyy0"1P' +0:paste register 1 to get last deletion +>BUFFER: doodleyankee +>CURSOR: 6 + + zletest $'yankee\eyyodoodle\edd"0p' +0:paste register 0 to get last yank +>BUFFER: yankee +>yankee +>CURSOR: 7 + + zletest $'err\eddahello\e"hddP' +0:setting named register also sets unnamed register +>BUFFER: hello +>CURSOR: 0 + + zletest $'first\e"ay0ddasecond\e"Add"aP' +0:appending to named register +>BUFFER: firs +>second +>CURSOR: 0 + + zletest $'word\e"a"byy"bp' +0:set one and then a different register +>BUFFER: word +>word +>CURSOR: 5 + + zletest $'i\exaar\e0"a"_cewn\eP' +0:set register then set black hole register +>BUFFER: win +>CURSOR: 1 + + zletest $'double\eyy"_"0P' +0:reset register after selecting black hole +>BUFFER: double +>double +>CURSOR: 0 + +# zsh works like vi here; in vim you get the concatenated string + zletest $'first\e"addasecond\eddP' +0:retrieve unnamed register after appending +>BUFFER: second +>CURSOR: 0 + + zletest $'Z\exayankee doodle\e"_db0"_yeP' +0:yank and delete to black hole register +>BUFFER: Zyankee e +>CURSOR: 0 + + zletest $'foo\eddabar\e"_p..' +0:paste from black hole register and repeat +>BUFFER: bar +>CURSOR: 2 + + zletest $'start\eFa"ac2lnew\eX"ap..' +0:repeat paste from named register +>BUFFER: stnwararart +>CURSOR: 9 + zletest $'word\euaend' 0:undo initial change >BUFFER: end