Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: Make yank zle params writable
- X-seq: zsh-workers 36699
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: zsh workers <zsh-workers@xxxxxxx>
- Subject: Re: PATCH: Make yank zle params writable
- Date: Tue, 29 Sep 2015 20:09:38 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=hX9arnuSuGDCVn0vCJb5nXdxsmi+t/BChX9VGKLCcV0=; b=faaU8UnYdB3LQJ1woHZcjdpMZJRZTJjs2QuWKKA8XKlco3CMC7FNGfLrbHnRuvd/PE WydAHbpHpR/zg89ifTpBr3U4oBFfSboCaesh7ERipm2rARZt9+QwlWqQ80nAS1oopV7m +v4IeM77tsALPxX+fuCNJwh2QI4mDVLuryuqHNzgj/f0b4OAA7hg1t5MDDgm1iTpOZPE ARsFmINwNqePAl09m2lwRxcSz/BZSqqfaQgIUtewi/CfAV5D7OR8/AGXgDeQ7GxI8z7d VqkJ8XyrIb0nncw/pZuQGQ4rHmRtmBVmbLmW+4M7LmspZZWeIIk5EoKSfF/vHfRJgUkP R6mQ==
- In-reply-to: <1443501793-29753-1-git-send-email-mikachu@gmail.com>
- 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: <1443501793-29753-1-git-send-email-mikachu@gmail.com>
On Tue, Sep 29, 2015 at 6:43 AM, Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> 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.)
>
> 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);
> }
Oops, this of course makes it so a widget can't see if the previous
widget (not called from inside it) set the yank state. So that was a
silly change... Hm, if we did this instead,
lastcmd &= ZLE_YANK;
then yank state is never unset automatically, because this part of the
code can't know if it was assigned the same value it already had, or
was just left alone.
This seems to work fine, using the w->flags variant from my zle -f
patch. I thought I could avoid that complication but I guess not. This
also means that setting YANK_ACTIVE inside a widget doesn't affect the
value you can read back from it (until you call another widget, at
least), and also that the yank state will be set correctly after
leaving even if you call widgets after assigning to it. So that's
probably all good.
It also looks like I had the before/after swapped in the code because
they refer to the yanked text, not the cursor. Here's an interdiff
because I'm lazy.
diff --git i/Src/Zle/zle_main.c w/Src/Zle/zle_main.c
index d605204..844984d 100644
--- i/Src/Zle/zle_main.c
+++ w/Src/Zle/zle_main.c
@@ -1422,7 +1422,6 @@ execzlefunc(Thingy func, char **args, int set_bindk)
while (*args)
addlinknode(largs, dupstring(*args++));
}
- lastcmd = 0;
startparamscope();
makezleparams(0);
sfcontext = SFC_WIDGET;
@@ -1431,6 +1430,8 @@ execzlefunc(Thingy func, char **args, int set_bindk)
opts[XTRACE] = oxt;
sfcontext = osc;
endparamscope();
+ lastcmd = w->flags;
+ w->flags = 0;
r = 1;
redup(osi, 0);
}
diff --git i/Src/Zle/zle_params.c w/Src/Zle/zle_params.c
index 1e95605..42d1b0b 100644
--- i/Src/Zle/zle_params.c
+++ w/Src/Zle/zle_params.c
@@ -506,7 +506,7 @@ get_yankend(UNUSED(Param pm))
static zlong
get_yankactive(UNUSED(Param pm))
{
- return !!(lastcmd & ZLE_YANK) + !!(lastcmd & ZLE_YANKBEFORE);
+ return !!(lastcmd & ZLE_YANK) + !!(lastcmd & ZLE_YANKAFTER);
}
/**/
@@ -527,11 +527,12 @@ set_yankend(UNUSED(Param pm), zlong 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;
+ if (bindk && bindk->widget) {
+ if (i == 1)
+ bindk->widget->flags |= ZLE_YANKBEFORE;
+ else if (i == 2)
+ bindk->widget->flags |= ZLE_YANKAFTER;
+ }
}
/**/
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author