From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7082 invoked by alias); 3 Sep 2015 10:38:55 -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: 36412 Received: (qmail 3945 invoked from network); 3 Sep 2015 10:38:54 -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=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-type:content-transfer-encoding; bh=EVxecluP6QjVPa1dp4MVjizBGE8D89oihbaF04Bf0Xg=; b=YxkB3L6QzYjvmIRbjS1FAL87Nz7i4Ccz3szDFqW2awK6bX19tftPfuKpNdUKQFtOkk aWm9r508q+DhAUfn88WAVHQpPRypXXVJpBG6lr6aBjFkYdAOSM+Ag3MFHF1wnotBC631 3wqNVyCG27ayOdS9Ngp31qrzSGVlQ32ongeoVy5mQ1tuhwQgiYoicl/MbTdmjiYDsvfc LxiUiegNbGJlYmJ7uaJr3vqohBQlEDMcidXoQaESTI9UTrctk7lFa5pISUyV55dEdQkk 9Ze35tZf3eDyazLILBvrrDalYOaRgRTb90QFPYUL9bwJ2PnVTd2r1vusBIP30djdXadY F88Q== X-Received: by 10.180.9.162 with SMTP id a2mr12521006wib.95.1441276728785; Thu, 03 Sep 2015 03:38:48 -0700 (PDT) From: Mikael Magnusson To: zsh-workers@zsh.org Subject: PATCH: zle -f from inside widget to set flags Date: Thu, 3 Sep 2015 12:38:23 +0200 Message-Id: <1441276703-23980-1-git-send-email-mikachu@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <150901163218.ZM2455@torch.brasslantern.com> References: <150901163218.ZM2455@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 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 need 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 that? 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 caseā„¢. 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] = oxt; sfcontext = osc; endparamscope(); - lastcmd = 0; + lastcmd = w->flags; + w->flags = 0; r = 1; redup(osi, 0); } @@ -1975,7 +1976,7 @@ zle_main_entry(int cmd, va_list ap) static struct builtin bintab[] = { BUILTIN("bindkey", 0, bin_bindkey, 0, -1, 0, "evaM:ldDANmrsLRp", NULL), 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(Options 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 = bindk->widget; + if (w) { + for (flag = args; *flag; flag++) { + if (!strcmp(*flag, "yank")) + w->flags |= ZLE_YANKBEFORE; + else if (!strcmp(*flag, "menucmp")) + w->flags |= ZLE_MENUCMP; + else if (!strcmp(*flag, "linemove")) + w->flags |= ZLE_LINEMOVE; + else if (!strcmp(*flag, "kill")) + w->flags |= ZLE_KILL; + else if (!strcmp(*flag, "keepsuffix")) + w->flags |= ZLE_KEEPSUFFIX; + else + zwarnnam(name, "invalid flag `%s' given to zle -f", *flag); + } + } + } +} + +/**/ +static int zle_usable() { return zleactive && !incompctlfunc && !incompfunc -- 2.5.0