From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28423 invoked by alias); 29 Sep 2015 04:43:35 -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: 36691 Received: (qmail 19409 invoked from network); 29 Sep 2015 04:43:33 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id; bh=fd5ZCcVGB6KmC5EalMd0uRY8gJbnjOd3C6upDGmVrZo=; b=whWUFYwMvpmm446O7nqfxreIRAw9Lx43ae8ESH995NZrg7KQvk/groqFYORqCxCaRU wdIDbYCjXNtQmZE/aVY8vsfFtPgUgP2TDaMPgbh0gONTAtMY+4Y8/SaLnXKyKNKTOmvq ekzfHy1dnXP7+g31JkRQuDRgd6f3WICkA1bm708OGM7IxO8aDBsq/rEqklobywjfJZOK el5+Xwnbw1sMo32ReVVQEd+no5pG1YeGyRV4ML2Kz/883VA+BvRWy3/eNqWZWEsU8AXh JSz1Q7TThUpjyqKiIb6e4zxlARkPUHp/8M6P8rZajEUDkRJQ2SCgDQ/jgcuLutjvmoSX PBzQ== X-Received: by 10.25.22.77 with SMTP id m74mr4410801lfi.10.1443501809677; Mon, 28 Sep 2015 21:43:29 -0700 (PDT) From: Mikael Magnusson To: zsh-workers@zsh.org Subject: PATCH: Make yank zle params writable Date: Tue, 29 Sep 2015 06:43:13 +0200 Message-Id: <1443501793-29753-1-git-send-email-mikachu@gmail.com> X-Mailer: git-send-email 2.5.0 Since these were added without much discussion, it seems a bit silly to add yet another interface (zle -f yank) to set them, so just make them writable. I haven't tried running with that movement of lastcmd in zle_main.c for a long time (approaching minutes), it is probably equivalent to not setting it at all there. However, with this change, it should be the case that all wrapper widgets retain the lastcmd state of the last internal widget they call, so things like kill-word multiple times will append instead of replace, etc. (I have not tested that particular thing.) --- Doc/Zsh/zle.yo | 5 ++++- Src/Zle/zle_main.c | 2 +- Src/Zle/zle_params.c | 39 ++++++++++++++++++++++++++++++++------- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index 7d95eb3..2ca2dc8 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -1013,7 +1013,8 @@ xitem(tt(YANK_START) (integer)) item(tt(YANK_END) (integer))( These three parameters indicate whether text has just been yanked (pasted) into the buffer. tt(YANK_START) and tt(YANK_END) are in the same units as -tt(CURSOR), and are only valid when tt(YANK_ACTIVE) is non-zero. +tt(CURSOR), and are only valid when tt(YANK_ACTIVE) is non-zero. They can +also be assigned to from widgets that insert text in a yank-like fashion, +for example wrappers of bracketed-paste. tt(YANK_ACTIVE) can be set to 1 +if the cursor is after the pasted text, or 2 if it is before the text. - -All three are read-only. ) diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c index 992f152..cdb2182 100644 --- a/Src/Zle/zle_main.c +++ b/Src/Zle/zle_main.c @@ -1394,6 +1394,7 @@ execzlefunc(Thingy func, char **args, int set_bindk) while (*args) addlinknode(largs, dupstring(*args++)); } + lastcmd = 0; startparamscope(); makezleparams(0); sfcontext = SFC_WIDGET; @@ -1402,7 +1403,6 @@ execzlefunc(Thingy func, char **args, int set_bindk) opts[XTRACE] = oxt; sfcontext = osc; endparamscope(); - lastcmd = 0; r = 1; redup(osi, 0); } diff --git a/Src/Zle/zle_params.c b/Src/Zle/zle_params.c index 000bc38..0c43dee 100644 --- a/Src/Zle/zle_params.c +++ b/Src/Zle/zle_params.c @@ -98,11 +98,11 @@ static const struct gsu_integer undo_change_no_gsu = static const struct gsu_integer undo_limit_no_gsu = { get_undo_limit_change, set_undo_limit_change, zleunsetfn }; static const struct gsu_integer yankstart_gsu = -{ get_yankstart, NULL, zleunsetfn }; +{ get_yankstart, set_yankstart, zleunsetfn }; static const struct gsu_integer yankend_gsu = -{ get_yankend, NULL, zleunsetfn }; +{ get_yankend, set_yankend, zleunsetfn }; static const struct gsu_integer yankactive_gsu = -{ get_yankactive, NULL, zleunsetfn }; +{ get_yankactive, set_yankactive, zleunsetfn }; static const struct gsu_array killring_gsu = { get_killring, set_killring, unset_killring }; @@ -149,9 +149,9 @@ static struct zleparam { { "WIDGET", PM_SCALAR | PM_READONLY, GSU(widget_gsu), NULL }, { "WIDGETFUNC", PM_SCALAR | PM_READONLY, GSU(widgetfunc_gsu), NULL }, { "WIDGETSTYLE", PM_SCALAR | PM_READONLY, GSU(widgetstyle_gsu), NULL }, - { "YANK_START", PM_INTEGER | PM_READONLY, GSU(yankstart_gsu), NULL }, - { "YANK_END", PM_INTEGER | PM_READONLY, GSU(yankend_gsu), NULL }, - { "YANK_ACTIVE", PM_INTEGER | PM_READONLY, GSU(yankactive_gsu), NULL }, + { "YANK_START", PM_INTEGER, GSU(yankstart_gsu), NULL }, + { "YANK_END", PM_INTEGER, GSU(yankend_gsu), NULL }, + { "YANK_ACTIVE", PM_INTEGER, GSU(yankactive_gsu), NULL }, { "ZLE_STATE", PM_SCALAR | PM_READONLY, GSU(zle_state_gsu), NULL }, { NULL, 0, NULL, NULL } }; @@ -503,7 +503,32 @@ get_yankend(UNUSED(Param pm)) static zlong get_yankactive(UNUSED(Param pm)) { - return lastcmd & ZLE_YANK; + return !!(lastcmd & ZLE_YANK) + !!(lastcmd & ZLE_YANKBEFORE); +} + +/**/ +static void +set_yankstart(UNUSED(Param pm), zlong i) +{ + yankb = i; +} + +/**/ +static void +set_yankend(UNUSED(Param pm), zlong i) +{ + yanke = i; +} + +/**/ +static void +set_yankactive(UNUSED(Param pm), zlong i) +{ + lastcmd &= ~ZLE_YANK; + if (i == 1) + lastcmd |= ZLE_YANKAFTER; + else if (i == 2) + lastcmd |= ZLE_YANKBEFORE; } /**/ -- 2.5.0