From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23703 invoked by alias); 3 Sep 2015 10:40:05 -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: 36413 Received: (qmail 2789 invoked from network); 3 Sep 2015 10:40:04 -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=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM 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=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=KN0laLlRFeJANJLpbHKIQxOsKosQSDmcKbrarcgYsyc=; b=lQXGUwppSAAguuRFUMtK1VgkH+wr/IjLIPIgqeMU5q5C5rz7TFPFrA0hGJQ3RBwAZn vn2hOQEtOwgbrU3jF9rlhYv8ut8QL2ur5NGbfXHvsDkGCrpPaFFCnX5y4jhLfGm4Oapv wlvgZfM/yIBIYuKtskprY6/pTokD/vt1OjHySkQg15kcUxyVjHXkgS72E2JqN6yt3QlE UpQ0tio8mWNCfz3HHe9L8n3aFj8/UvmvPqAcxKtxMOj1pSc703VMJbhoTWqV0C4uIg0t /2D7pTbbrd9eAHovIk97mEPURYDrXwOIgSYudiYXixEmWGHBKU/AlruOrc8RXtO4D5bv ljqg== MIME-Version: 1.0 X-Received: by 10.55.221.8 with SMTP id n8mr37938399qki.85.1441276800662; Thu, 03 Sep 2015 03:40:00 -0700 (PDT) In-Reply-To: <1441276703-23980-1-git-send-email-mikachu@gmail.com> References: <150901163218.ZM2455@torch.brasslantern.com> <1441276703-23980-1-git-send-email-mikachu@gmail.com> Date: Thu, 3 Sep 2015 12:40:00 +0200 Message-ID: Subject: Re: PATCH: zle -f from inside widget to set flags From: Mikael Magnusson To: zsh workers Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Thu, Sep 3, 2015 at 12:38 PM, Mikael Magnusson wrote= : > This works for "yank", if you inserted text with another yank widget. > > It's not very likely to do anything useful for "keepsuffix", since the > code that handles that flag only triggers for internal widgets, so we nee= d > to fiddle some more with that path. I don't really know what menucmp, > linemove and kill are for. The others seemed definitely not useful, > but I could be wrong. > > Thoughts? Am I correct in assuming it's pretty safe to use bindk like tha= t? > > We could potentially pass yankb and yanke as arguments like zle -f > yank15:36 (but with some nicer syntax) to make it work in the general cas= e=E2=84=A2. I haven't tried, but I highly suspect that if you call another user widget, and that widget uses zle -f, then this won't have any effect since the parent widget's flags will trump those. That's probably okay. If not, we could add a 'zle -f copy' that sticks lastcmd in w->flags (not tested). > Src/Zle/zle_main.c | 5 +++-- > Src/Zle/zle_thingy.c | 33 +++++++++++++++++++++++++++++++++ > 2 files changed, 36 insertions(+), 2 deletions(-) > > diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c > index 5440a48..af878eb 100644 > --- a/Src/Zle/zle_main.c > +++ b/Src/Zle/zle_main.c > @@ -1396,7 +1396,8 @@ execzlefunc(Thingy func, char **args, int set_bindk= ) > opts[XTRACE] =3D oxt; > sfcontext =3D osc; > endparamscope(); > - lastcmd =3D 0; > + lastcmd =3D w->flags; > + w->flags =3D 0; > r =3D 1; > redup(osi, 0); > } > @@ -1975,7 +1976,7 @@ zle_main_entry(int cmd, va_list ap) > static struct builtin bintab[] =3D { > BUILTIN("bindkey", 0, bin_bindkey, 0, -1, 0, "evaM:ldDANmrsLRp", NUL= L), > BUILTIN("vared", 0, bin_vared, 1, 1, 0, "aAcef:hi:M:m:p:r:t:", = NULL), > - BUILTIN("zle", 0, bin_zle, 0, -1, 0, "aAcCDFgGIKlLmMNrRTUw",= NULL), > + BUILTIN("zle", 0, bin_zle, 0, -1, 0, "aAcCDfFgGIKlLmMNrRTUw"= , NULL), > }; > > /* The order of the entries in this table has to match the *HOOK > diff --git a/Src/Zle/zle_thingy.c b/Src/Zle/zle_thingy.c > index 7fd3a59..8b7390c 100644 > --- a/Src/Zle/zle_thingy.c > +++ b/Src/Zle/zle_thingy.c > @@ -352,6 +352,7 @@ bin_zle(char *name, char **args, Options ops, UNUSED(= int func)) > { 'U', bin_zle_unget, 1, 1 }, > { 'K', bin_zle_keymap, 1, 1 }, > { 'I', bin_zle_invalidate, 0, 0 }, > + { 'f', bin_zle_flags, 1, -1 }, > { 'F', bin_zle_fd, 0, 2 }, > { 'T', bin_zle_transform, 0, 2}, > { 0, bin_zle_call, 0, -1 }, > @@ -625,6 +626,38 @@ bin_zle_complete(char *name, char **args, UNUSED(Opt= ions ops), UNUSED(char func) > > /**/ > static int > +bin_zle_flags(char *name, char **args, UNUSED(Options ops), UNUSED(char = func)) > +{ > + char **flag; > + > + if (!zle_usable()) { > + zwarnnam(name, "can only set flags from a widget"); > + return 1; > + } > + > + if (bindk) { > + Widget w =3D bindk->widget; > + if (w) { > + for (flag =3D args; *flag; flag++) { > + if (!strcmp(*flag, "yank")) > + w->flags |=3D ZLE_YANKBEFORE; > + else if (!strcmp(*flag, "menucmp")) > + w->flags |=3D ZLE_MENUCMP; > + else if (!strcmp(*flag, "linemove")) > + w->flags |=3D ZLE_LINEMOVE; > + else if (!strcmp(*flag, "kill")) > + w->flags |=3D ZLE_KILL; > + else if (!strcmp(*flag, "keepsuffix")) > + w->flags |=3D ZLE_KEEPSUFFIX; > + else > + zwarnnam(name, "invalid flag `%s' given to zle -f", *= flag); > + } > + } > + } > +} > + > +/**/ > +static int > zle_usable() > { > return zleactive && !incompctlfunc && !incompfunc > -- > 2.5.0 > --=20 Mikael Magnusson