zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: Make yank zle params writable
@ 2015-09-29  4:43 Mikael Magnusson
  2015-09-29  4:43 ` PATCH: Add a much simpler alternative to using url-quote-magic + bracketed-paste-magic Mikael Magnusson
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Mikael Magnusson @ 2015-09-29  4:43 UTC (permalink / raw)
  To: zsh-workers

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.)

---
 Doc/Zsh/zle.yo       |  5 ++++-
 Src/Zle/zle_main.c   |  2 +-
 Src/Zle/zle_params.c | 39 ++++++++++++++++++++++++++++++++-------
 3 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo
index 7d95eb3..2ca2dc8 100644
--- a/Doc/Zsh/zle.yo
+++ b/Doc/Zsh/zle.yo
@@ -1013,7 +1013,8 @@ xitem(tt(YANK_START) (integer))
 item(tt(YANK_END) (integer))(
 These three parameters indicate whether text has just been yanked (pasted)
 into the buffer.  tt(YANK_START) and tt(YANK_END) are in the same units as
-tt(CURSOR), and are only valid when tt(YANK_ACTIVE) is non-zero.
+tt(CURSOR), and are only valid when tt(YANK_ACTIVE) is non-zero.  They can
+also be assigned to from widgets that insert text in a yank-like fashion,
+for example wrappers of bracketed-paste.  tt(YANK_ACTIVE) can be set to 1
+if the cursor is after the pasted text, or 2 if it is before the text.
-
-All three are read-only.
 )
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);
 	}
diff --git a/Src/Zle/zle_params.c b/Src/Zle/zle_params.c
index 000bc38..0c43dee 100644
--- a/Src/Zle/zle_params.c
+++ b/Src/Zle/zle_params.c
@@ -98,11 +98,11 @@ static const struct gsu_integer undo_change_no_gsu =
 static const struct gsu_integer undo_limit_no_gsu =
 { get_undo_limit_change, set_undo_limit_change, zleunsetfn };
 static const struct gsu_integer yankstart_gsu =
-{ get_yankstart, NULL, zleunsetfn };
+{ get_yankstart, set_yankstart, zleunsetfn };
 static const struct gsu_integer yankend_gsu =
-{ get_yankend, NULL, zleunsetfn };
+{ get_yankend, set_yankend, zleunsetfn };
 static const struct gsu_integer yankactive_gsu =
-{ get_yankactive, NULL, zleunsetfn };
+{ get_yankactive, set_yankactive, zleunsetfn };
 
 static const struct gsu_array killring_gsu =
 { get_killring, set_killring, unset_killring };
@@ -149,9 +149,9 @@ static struct zleparam {
     { "WIDGET", PM_SCALAR | PM_READONLY, GSU(widget_gsu), NULL },
     { "WIDGETFUNC", PM_SCALAR | PM_READONLY, GSU(widgetfunc_gsu), NULL },
     { "WIDGETSTYLE", PM_SCALAR | PM_READONLY, GSU(widgetstyle_gsu), NULL },
-    { "YANK_START", PM_INTEGER | PM_READONLY, GSU(yankstart_gsu), NULL },
-    { "YANK_END", PM_INTEGER | PM_READONLY, GSU(yankend_gsu), NULL },
-    { "YANK_ACTIVE", PM_INTEGER | PM_READONLY, GSU(yankactive_gsu), NULL },
+    { "YANK_START", PM_INTEGER, GSU(yankstart_gsu), NULL },
+    { "YANK_END", PM_INTEGER, GSU(yankend_gsu), NULL },
+    { "YANK_ACTIVE", PM_INTEGER, GSU(yankactive_gsu), NULL },
     { "ZLE_STATE", PM_SCALAR | PM_READONLY, GSU(zle_state_gsu), NULL },
     { NULL, 0, NULL, NULL }
 };
@@ -503,7 +503,32 @@ get_yankend(UNUSED(Param pm))
 static zlong
 get_yankactive(UNUSED(Param pm))
 {
-    return lastcmd & ZLE_YANK;
+    return !!(lastcmd & ZLE_YANK) + !!(lastcmd & ZLE_YANKBEFORE);
+}
+
+/**/
+static void
+set_yankstart(UNUSED(Param pm), zlong i)
+{
+    yankb = i;
+}
+
+/**/
+static void
+set_yankend(UNUSED(Param pm), zlong i)
+{
+    yanke = 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;
 }
 
 /**/
-- 
2.5.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* PATCH: Add a much simpler alternative to using url-quote-magic + bracketed-paste-magic
  2015-09-29  4:43 PATCH: Make yank zle params writable Mikael Magnusson
@ 2015-09-29  4:43 ` Mikael Magnusson
  2015-09-29 18:09 ` PATCH: Make yank zle params writable Mikael Magnusson
  2015-09-30  1:15 ` Mikael Magnusson
  2 siblings, 0 replies; 10+ messages in thread
From: Mikael Magnusson @ 2015-09-29  4:43 UTC (permalink / raw)
  To: zsh-workers

Now that we have more control over the yank highlighting, we can handle pasted
urls directly, instead of mucking around with pretending we don't know which
text was pasted together, then trying to reverse engineer this fact from it looking
like a url. This function simply looks at the first few characters and if they
match the configured schemas, then the paste is quoted.

It handles NUMERIC to quote, but not any weird vi or newline stripping stuff.

---
 Functions/Zle/bracketed-paste-url-magic | 38 +++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 Functions/Zle/bracketed-paste-url-magic

diff --git a/Functions/Zle/bracketed-paste-url-magic b/Functions/Zle/bracketed-paste-url-magic
new file mode 100644
index 0000000..e05e982
--- /dev/null
+++ b/Functions/Zle/bracketed-paste-url-magic
@@ -0,0 +1,38 @@
+# bracketed-paste-url-magic quotes pasted urls automatically, if the
+# paste exactly starts with a url, eg no spaces or other characters precede it
+#
+# To use it, put this in your startup files (eg, .zshrc)
+#
+# autoload -Uz bracketed-paste-url-magic
+# zle -N bracketed-paste bracketed-paste-url-magic
+#
+# You can customize which schemas are to be quoted by using
+#
+# zstyle :bracketed-paste-url-magic schema http https ftp
+#
+# The default can be seen just below.
+
+local -a schema
+zstyle -a :bracketed-paste-url-magic schema schema || schema=(http https ftp ftps file ssh sftp)
+
+local wantquote=${NUMERIC:-0}
+local content
+local start=$#LBUFFER
+
+zle .$WIDGET -N content
+
+if ! (( $wantquote )); then
+  if [[ $content = (${(~j:|:)schema})://* ]]; then
+    wantquote=1
+  fi
+fi
+
+if (( $wantquote )); then
+  content=${(q-)content}
+fi
+
+LBUFFER+=$content
+
+YANK_START=$start
+YANK_END=$#LBUFFER
+YANK_ACTIVE=1
-- 
2.5.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: PATCH: Make yank zle params writable
  2015-09-29  4:43 PATCH: Make yank zle params writable Mikael Magnusson
  2015-09-29  4:43 ` PATCH: Add a much simpler alternative to using url-quote-magic + bracketed-paste-magic Mikael Magnusson
@ 2015-09-29 18:09 ` Mikael Magnusson
  2015-09-30  1:15 ` Mikael Magnusson
  2 siblings, 0 replies; 10+ messages in thread
From: Mikael Magnusson @ 2015-09-29 18:09 UTC (permalink / raw)
  To: zsh workers

On Tue, Sep 29, 2015 at 6:43 AM, Mikael Magnusson <mikachu@gmail.com> 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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: PATCH: Make yank zle params writable
  2015-09-29  4:43 PATCH: Make yank zle params writable Mikael Magnusson
  2015-09-29  4:43 ` PATCH: Add a much simpler alternative to using url-quote-magic + bracketed-paste-magic Mikael Magnusson
  2015-09-29 18:09 ` PATCH: Make yank zle params writable Mikael Magnusson
@ 2015-09-30  1:15 ` Mikael Magnusson
  2015-09-30  2:06   ` PATCH: zle -f from inside widget to set flags and make yank start/end " Mikael Magnusson
  2 siblings, 1 reply; 10+ messages in thread
From: Mikael Magnusson @ 2015-09-30  1:15 UTC (permalink / raw)
  To: zsh workers

On Tue, Sep 29, 2015 at 6:43 AM, Mikael Magnusson <mikachu@gmail.com> 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've thought about this some more, and I'm not sure which route to go,
wrt YANK_ACTIVE. It might be better to implement the zle -f interface
after all, if we find we do want to set other flags. If we had
YANK_ACTIVE writable then, we'd have two different interfaces for
setting different bits of the same variable, which might be even more
silly. I think I shall go the route of implementing zle -f
yank(before/after)/kill (I haven't seen evidence of others being
useful yet), and applying this patch (plus later amendments), apart
from the writable part of YANK_ACTIVE. It seems nobody else has strong
opinions about this, but sorry for going back and forth so much about
it :).

It probably also makes more sense to have a separate thing to set the
flag than to read it, since you're reading what the flag was before
entering this widget, but setting what it will be after it finishes.

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 10+ messages in thread

* PATCH: zle -f from inside widget to set flags and make yank start/end zle params writable
  2015-09-30  1:15 ` Mikael Magnusson
@ 2015-09-30  2:06   ` Mikael Magnusson
  2015-10-01 15:33     ` Jun T.
  0 siblings, 1 reply; 10+ messages in thread
From: Mikael Magnusson @ 2015-09-30  2:06 UTC (permalink / raw)
  To: zsh-workers

I feel better about this interface, I think. And as a bonus, I did add
the 'kill' option for zle -f too (even tested it this time, and it does
work and fixes that problem for wrap widgets).

This is mostly the same as earlier patches I've sent but this version
now actually allows you to highlight a custom region, rather than having
to set CUTBUFFER and invoke 'zle .yank'.

'yank-pop' seems to work, although it is not a widget I ever use so
I can't say if it's working _sanely_. I did at one point manage to get
into a state where part of the commandline didn't even have the "default"
style, but I think (hope) that's not the fault of this patch.

---
 Doc/Zsh/zle.yo                          | 21 +++++++++++++-----
 Functions/Zle/bracketed-paste-url-magic | 38 ++++++++++++++++++++++++++++++++
 Src/Zle/zle_main.c                      |  5 +++--
 Src/Zle/zle_params.c                    | 24 +++++++++++++++-----
 Src/Zle/zle_thingy.c                    | 39 +++++++++++++++++++++++++++++++++
 5 files changed, 115 insertions(+), 12 deletions(-)
 create mode 100644 Functions/Zle/bracketed-paste-url-magic

NB, I see now I forgot to wrap the text in zle.yo, I'll do that before pushing.

diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo
index 7d95eb3..0e4caec 100644
--- a/Doc/Zsh/zle.yo
+++ b/Doc/Zsh/zle.yo
@@ -404,6 +404,7 @@ xitem(tt(zle) tt(-l) [ tt(-L) | tt(-a) ] [ var(string) ... ])
 xitem(tt(zle) tt(-D) var(widget) ...)
 xitem(tt(zle) tt(-A) var(old-widget) var(new-widget))
 xitem(tt(zle) tt(-N) var(widget) [ var(function) ])
+xitem(tt(zle) tt(-f) var(flag) [ var(flag)... ])
 xitem(tt(zle) tt(-C) var(widget) var(completion-widget) var(function))
 xitem(tt(zle) tt(-R) [ tt(-c) ] [ var(display-string) ] [ var(string) ... ])
 xitem(tt(zle) tt(-M) var(string))
@@ -464,6 +465,13 @@ ifzman(the section `Widgets' below)\
 ifnzman(noderef(Zle Widgets))\
 .
 )
+item(tt(-f) var(flag) [ var(flag)... ])(
+Set various flags on the running widget.  Possible values for var(flag) are:
+
+tt(yank) for indicating that the widget has yanked text into the buffer.  If the widget is wrapping an existing internal widget, no further action is necessary, but if it has inserted the text manually, then it should also take care to set tt(YANK_START) and tt(YANK_END) correctly.  tt(yankbefore) does the same but is used when the yanked text appears after the cursor.
+
+tt(kill) for indicating that text has been killed into the cutbuffer.  When repeatedly invoking a kill widget, text is appended to the cutbuffer instead of replacing it, but when wrapping such widgets, it is necessary to call `tt(zle -f kill)' to retain this effect.
+)
 cindex(completion widgets, creating)
 item(tt(-C) var(widget) var(completion-widget) var(function))(
 Create a user-defined completion widget named var(widget). The 
@@ -1011,11 +1019,14 @@ vindex(YANK_END)
 xitem(tt(YANK_ACTIVE) (integer))
 xitem(tt(YANK_START) (integer))
 item(tt(YANK_END) (integer))(
-These three parameters indicate whether text has just been yanked (pasted)
-into the buffer.  tt(YANK_START) and tt(YANK_END) are in the same units as
-tt(CURSOR), and are only valid when tt(YANK_ACTIVE) is non-zero.
-
-All three are read-only.
+tt(YANK_ACTIVE) indicates whether text has just been yanked (pasted)
+into the buffer.  tt(YANK_START) and tt(YANK_END) give the location of
+the pasted text and are in the same units as tt(CURSOR).  They are only
+valid for reading when tt(YANK_ACTIVE) is non-zero.  They can also be
+assigned by widgets that insert text in a yank-like fashion, for example
+wrappers of tt(bracketed-paste).  See also tt(zle -f).
+
+tt(YANK_ACTIVE) is read-only.
 )
 vindex(ZLE_STATE)
 item(tt(ZLE_STATE) (scalar))(
diff --git a/Functions/Zle/bracketed-paste-url-magic b/Functions/Zle/bracketed-paste-url-magic
new file mode 100644
index 0000000..b952d84
--- /dev/null
+++ b/Functions/Zle/bracketed-paste-url-magic
@@ -0,0 +1,38 @@
+# bracketed-paste-url-magic quotes pasted urls automatically, if the
+# paste exactly starts with a url, eg no spaces or other characters precede it
+#
+# To use it, put this in your startup files (eg, .zshrc)
+#
+# autoload -Uz bracketed-paste-url-magic
+# zle -N bracketed-paste bracketed-paste-url-magic
+#
+# You can customize which schemas are to be quoted by using
+#
+# zstyle :bracketed-paste-url-magic schema http https ftp
+#
+# The default can be seen just below.
+
+local -a schema
+zstyle -a :bracketed-paste-url-magic schema schema || schema=(http https ftp ftps file ssh sftp)
+
+local wantquote=${NUMERIC:-0}
+local content
+local start=$#LBUFFER
+
+zle .$WIDGET -N content
+
+if ! (( $wantquote )); then
+  if [[ $content = (${(~j:|:)schema})://* ]]; then
+    wantquote=1
+  fi
+fi
+
+if (( $wantquote )); then
+  content=${(q-)content}
+fi
+
+LBUFFER+=$content
+
+YANK_START=$start
+YANK_END=$#LBUFFER
+zle -f yank
diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index 992f152..593d636 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -1402,7 +1402,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);
 	}
@@ -1981,7 +1982,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_params.c b/Src/Zle/zle_params.c
index 000bc38..b5bb288 100644
--- a/Src/Zle/zle_params.c
+++ b/Src/Zle/zle_params.c
@@ -98,9 +98,9 @@ static const struct gsu_integer undo_change_no_gsu =
 static const struct gsu_integer undo_limit_no_gsu =
 { get_undo_limit_change, set_undo_limit_change, zleunsetfn };
 static const struct gsu_integer yankstart_gsu =
-{ get_yankstart, NULL, zleunsetfn };
+{ get_yankstart, set_yankstart, zleunsetfn };
 static const struct gsu_integer yankend_gsu =
-{ get_yankend, NULL, zleunsetfn };
+{ get_yankend, set_yankend, zleunsetfn };
 static const struct gsu_integer yankactive_gsu =
 { get_yankactive, NULL, zleunsetfn };
 
@@ -149,8 +149,8 @@ static struct zleparam {
     { "WIDGET", PM_SCALAR | PM_READONLY, GSU(widget_gsu), NULL },
     { "WIDGETFUNC", PM_SCALAR | PM_READONLY, GSU(widgetfunc_gsu), NULL },
     { "WIDGETSTYLE", PM_SCALAR | PM_READONLY, GSU(widgetstyle_gsu), NULL },
-    { "YANK_START", PM_INTEGER | PM_READONLY, GSU(yankstart_gsu), NULL },
-    { "YANK_END", PM_INTEGER | PM_READONLY, GSU(yankend_gsu), NULL },
+    { "YANK_START", PM_INTEGER, GSU(yankstart_gsu), NULL },
+    { "YANK_END", PM_INTEGER, GSU(yankend_gsu), NULL },
     { "YANK_ACTIVE", PM_INTEGER | PM_READONLY, GSU(yankactive_gsu), NULL },
     { "ZLE_STATE", PM_SCALAR | PM_READONLY, GSU(zle_state_gsu), NULL },
     { NULL, 0, NULL, NULL }
@@ -503,7 +503,21 @@ get_yankend(UNUSED(Param pm))
 static zlong
 get_yankactive(UNUSED(Param pm))
 {
-    return lastcmd & ZLE_YANK;
+    return !!(lastcmd & ZLE_YANK) + !!(lastcmd & ZLE_YANKAFTER);
+}
+
+/**/
+static void
+set_yankstart(UNUSED(Param pm), zlong i)
+{
+    yankb = i;
+}
+
+/**/
+static void
+set_yankend(UNUSED(Param pm), zlong i)
+{
+    yanke = i;
 }
 
 /**/
diff --git a/Src/Zle/zle_thingy.c b/Src/Zle/zle_thingy.c
index da3a6d4..3963d7e 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,44 @@ 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_YANKAFTER;
+		} else if (!strcmp(*flag, "yankbefore"))
+		    w->flags |= ZLE_YANKBEFORE;
+		else if (!strcmp(*flag, "kill"))
+		    w->flags |= ZLE_KILL;
+		/*
+		 * These won't do anything yet, because of how execzlefunc
+		 * handles user widgets
+		} else if (!strcmp(*flag, "menucmp"))
+		    w->flags |= ZLE_MENUCMP;
+		else if (!strcmp(*flag, "linemove"))
+		    w->flags |= ZLE_LINEMOVE;
+		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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: PATCH: zle -f from inside widget to set flags and make yank start/end zle params writable
  2015-09-30  2:06   ` PATCH: zle -f from inside widget to set flags and make yank start/end " Mikael Magnusson
@ 2015-10-01 15:33     ` Jun T.
  2015-10-01 19:43       ` Mikael Magnusson
  0 siblings, 1 reply; 10+ messages in thread
From: Jun T. @ 2015-10-01 15:33 UTC (permalink / raw)
  To: zsh-workers

I'm getting the following warning:

zle_thingy.c:663:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^

Maybe return 1 for invalid flag, and 0 otherwise.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: PATCH: zle -f from inside widget to set flags and make yank start/end zle params writable
  2015-10-01 15:33     ` Jun T.
@ 2015-10-01 19:43       ` Mikael Magnusson
  2015-10-02  8:09         ` Jun T.
  0 siblings, 1 reply; 10+ messages in thread
From: Mikael Magnusson @ 2015-10-01 19:43 UTC (permalink / raw)
  To: Jun T.; +Cc: zsh workers

On Thu, Oct 1, 2015 at 5:33 PM, Jun T. <takimoto-j@kba.biglobe.ne.jp> wrote:
> I'm getting the following warning:
>
> zle_thingy.c:663:1: warning: control may reach end of non-void function [-Wreturn-type]
> }
> ^
>
> Maybe return 1 for invalid flag, and 0 otherwise.

Yeah, danielsh also pointed this out to me. I didn't realize configure
doesn't enable any warnings by default.

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: PATCH: zle -f from inside widget to set flags and make yank start/end zle params writable
  2015-10-01 19:43       ` Mikael Magnusson
@ 2015-10-02  8:09         ` Jun T.
  2015-10-02 18:43           ` Mikael Magnusson
  0 siblings, 1 reply; 10+ messages in thread
From: Jun T. @ 2015-10-02  8:09 UTC (permalink / raw)
  To: zsh-workers

I've been using clang, but if I switch to gcc I get another warning:

zle_thingy.c:671: warning: ‘zle_usable’ was used with no prototype before its definition

Sorry for not reporting this with the previous one, but anyway
this can be stopped by using func(void) instead of func():

static int
zle_usable(void)


On 2015/10/02, at 4:43, Mikael Magnusson <mikachu@gmail.com> wrote:
> I didn't realize configure
> doesn't enable any warnings by default.

configure adds -Wall -Wmissing-prototypes to CFLAGS only if CFLAGS
is not specified by the user (lines 474 and below in configure.ac).

I guess you specify CFLAGS by yourself (in environment?); then
you need to explicitly include -Wxxx in CFLAGS.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: PATCH: zle -f from inside widget to set flags and make yank start/end zle params writable
  2015-10-02  8:09         ` Jun T.
@ 2015-10-02 18:43           ` Mikael Magnusson
  2015-10-02 19:58             ` Jun T.
  0 siblings, 1 reply; 10+ messages in thread
From: Mikael Magnusson @ 2015-10-02 18:43 UTC (permalink / raw)
  To: Jun T.; +Cc: zsh-workers

On Fri, Oct 2, 2015 at 10:09 AM, Jun T. <takimoto-j@kba.biglobe.ne.jp> wrote:
> I've been using clang, but if I switch to gcc I get another warning:
>
> zle_thingy.c:671: warning: ‘zle_usable’ was used with no prototype before its definition
>
> Sorry for not reporting this with the previous one, but anyway
> this can be stopped by using func(void) instead of func():
>
> static int
> zle_usable(void)

I moved the definition up so it's not used before being defined instead.

> On 2015/10/02, at 4:43, Mikael Magnusson <mikachu@gmail.com> wrote:
>> I didn't realize configure
>> doesn't enable any warnings by default.
>
> configure adds -Wall -Wmissing-prototypes to CFLAGS only if CFLAGS
> is not specified by the user (lines 474 and below in configure.ac).
>
> I guess you specify CFLAGS by yourself (in environment?); then
> you need to explicitly include -Wxxx in CFLAGS.

I guess so, most projects add their warning flags regardless.

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: PATCH: zle -f from inside widget to set flags and make yank start/end zle params writable
  2015-10-02 18:43           ` Mikael Magnusson
@ 2015-10-02 19:58             ` Jun T.
  0 siblings, 0 replies; 10+ messages in thread
From: Jun T. @ 2015-10-02 19:58 UTC (permalink / raw)
  To: zsh-workers


2015/10/03 03:43, Mikael Magnusson <mikachu@gmail.com> wrote:

> I moved the definition up so it's not used before being defined instead.

It's been pushed already so this is just a comment but, in general,
it would be better to use zle_usable(void) because then the correct
prototype is generated in zle_thingy.pro and, in the future, anyone
can call zle_usable() from anywhere in zle_thingy.c. I think it's
the main reason that there is a /**/ in front of the definition.

But there are several functions in the zsh source which are defined as
func() instead of func(void). So we may not need to be so strict here.


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-10-02 19:59 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-29  4:43 PATCH: Make yank zle params writable Mikael Magnusson
2015-09-29  4:43 ` PATCH: Add a much simpler alternative to using url-quote-magic + bracketed-paste-magic Mikael Magnusson
2015-09-29 18:09 ` PATCH: Make yank zle params writable Mikael Magnusson
2015-09-30  1:15 ` Mikael Magnusson
2015-09-30  2:06   ` PATCH: zle -f from inside widget to set flags and make yank start/end " Mikael Magnusson
2015-10-01 15:33     ` Jun T.
2015-10-01 19:43       ` Mikael Magnusson
2015-10-02  8:09         ` Jun T.
2015-10-02 18:43           ` Mikael Magnusson
2015-10-02 19:58             ` Jun T.

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).