From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24644 invoked by alias); 31 Aug 2015 07:54:13 -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: 36343 Received: (qmail 17518 invoked from network); 31 Aug 2015 07:54:12 -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=vUNFlQM5l/NNSIrNlN40jdI3fN1K0ZXmg774YwGgfGc=; b=DYuzeYd4hL2jPWC+L+ORkuqMIPTD76x+b1Ox3Ngbdh8lpQpnJ1II17gGwI2RIB7Vvl Pje2q3NlM+CGr4WBTlOBF1i/8Iptw6HjUD+EJ1xUIZUSW45xMU6Zjb9p0MbkwZuFrlbD XJDEhHV54w3zAdpP5TN15cF5crLyibce48mTNmYBWYzD46kXhD8yqfGV+38KqqRKHHMK WkaGKvR9IIbVCPvG8S9u62f/XIgatRRUhG1ZCbkss9vtzoMXEyyF0PhPmYk3JgJ9H7NU szP2x+Syamg83FgEC7LmcnPr3avkjq0dFRE2qBBR7rasKDkhRTXfpmq/ez32GH+erS/q xmaA== X-Received: by 10.181.12.5 with SMTP id em5mr17709564wid.67.1441007648031; Mon, 31 Aug 2015 00:54:08 -0700 (PDT) From: Mikael Magnusson To: zsh-workers@zsh.org Subject: PATCH: Implement zle -P Date: Mon, 31 Aug 2015 09:54:02 +0200 Message-Id: <1441007642-12365-1-git-send-email-mikachu@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <101231002820.ZM7583@torch.brasslantern.com> References: <101231002820.ZM7583@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This lets you say % zle -P mywidget prototypewidget myfunction and it will work like zle -N mywidget myfunction except it will behave like prototypewidget in Various Ways™. --- I haven't tested this much (for completion functions, not at all) yet, but it works for the case in the current thread, see example at the bottom. Does it look overall sane? I'm not very sure on which/how/where all these flags are checked and set. The final argument should probably be optional and default to the first, like for zle -N, but zle -C doesn't seem to do that, and that's the code I mostly copied. I don't see any reason to change zle -N to call into zle -P internally though. % zle -P myyank yank myyank % myyank () { zle -M hello local oldbuf=$CUTBUFFER CUTBUFFER=${(U)CUTBUFFER zle .yank CUTBUFFER=$oldbuf } # put asdfdδ in the cutbuffer here # press yank and myyank alternatingly % asdfdδASDFDΔASDFDΔASDFDΔasdfdδasdfdδasdfdδASDFDΔASDFDΔASDFDΔ # each word gets highlighted appropriately in both cases Src/Zle/zle_main.c | 5 +++-- Src/Zle/zle_thingy.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c index c1b70e7..d4592ba 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; + if (!(w->flags & ZLE_NOTCOMMAND)) + lastcmd = w->flags; 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, "aAcCDFgGIKlLmMNPrRTUw", 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..e648838 100644 --- a/Src/Zle/zle_thingy.c +++ b/Src/Zle/zle_thingy.c @@ -347,6 +347,7 @@ bin_zle(char *name, char **args, Options ops, UNUSED(int func)) { 'A', bin_zle_link, 2, 2 }, { 'N', bin_zle_new, 1, 2 }, { 'C', bin_zle_complete, 3, 3 }, + { 'P', bin_zle_prototype, 3, 3}, { 'R', bin_zle_refresh, 0, -1 }, { 'M', bin_zle_mesg, 1, 1 }, { 'U', bin_zle_unget, 1, 1 }, @@ -591,6 +592,42 @@ bin_zle_new(char *name, char **args, UNUSED(Options ops), UNUSED(char func)) /**/ static int +bin_zle_prototype(char *name, char **args, UNUSED(Options ops), UNUSED(char func)) +{ + Thingy t; + Widget w, pw; + + t = rthingy((args[1][0] == '.') ? args[1] : dyncat(".", args[1])); + pw = t->widget; + unrefthingy(t); + + if (!pw) { + zwarnnam(name, "invalid widget `%s'", args[1]); + return 1; + } + w = zalloc(sizeof(*w)); + w->flags = pw->flags & ~WIDGET_INT; + w->first = NULL; + if (w->flags & WIDGET_NCOMP) { + w->u.comp.fn = pw->u.fn; + w->u.comp.wid = ztrdup(args[1]); + w->u.comp.func = ztrdup(args[2]); + } else { + w->u.fnnam = ztrdup(args[2]); + } + if (bindwidget(w, rthingy(args[0]))) { + freewidget(w); + zwarnnam(name, "widget name `%s' is protected", args[0]); + return 1; + } + if (w->flags & WIDGET_NCOMP) + hascompwidgets++; + + return 0; +} + +/**/ +static int bin_zle_complete(char *name, char **args, UNUSED(Options ops), UNUSED(char func)) { Thingy t; -- 2.5.0