Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: zle -f from inside widget to set flags
- X-seq: zsh-workers 36412
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: PATCH: zle -f from inside widget to set flags
- Date: Thu, 3 Sep 2015 12:38:23 +0200
- 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==
- In-reply-to: <150901163218.ZM2455@torch.brasslantern.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: <150901163218.ZM2455@torch.brasslantern.com>
---
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author