Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: Set completion function flags correctly for zle -P



On Mon, Aug 31, 2015 at 11:55 AM, Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> ---
>
> This appears to work better.
>
>  Src/Zle/zle_thingy.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/Src/Zle/zle_thingy.c b/Src/Zle/zle_thingy.c
> index e648838..0401099 100644
> --- a/Src/Zle/zle_thingy.c
> +++ b/Src/Zle/zle_thingy.c
> @@ -606,9 +606,10 @@ bin_zle_prototype(char *name, char **args, UNUSED(Options ops), UNUSED(char func
>         return 1;
>      }
>      w = zalloc(sizeof(*w));
> -    w->flags = pw->flags & ~WIDGET_INT;
> +    w->flags = pw->flags & ~(WIDGET_INT|ZLE_ISCOMP);
>      w->first = NULL;
> -    if (w->flags & WIDGET_NCOMP) {
> +    if (pw->flags & ZLE_ISCOMP) {
> +       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]);

Here's the final(?) touchup, not counting documentation. It makes the
last argument optional. Maybe it would be better to make the middle
argument optional? Not sure. (This one will be whitespace damaged.)

I can now do this (which is why I originally found this old thread, if
anyone was curious):

function _start_paste() {
  local content
  local a b
  local oldcutbuf="$CUTBUFFER"
  # I haven't quite decided how I want to control quoting yet.
  [[ $_SPACE_AFTER_PASTE_QUOTE = 1 ]]; a=$?
  (( $+NUMERIC )) || [[ $KEYS = $'\e\e'* ]]; b=$?
  zle .$WIDGET -N content
  if [[ $a -ne $b ]]; then
    CUTBUFFER=${(q-)content}' '
  else
    CUTBUFFER=$content
  fi
  zle .yank
  CUTBUFFER="$oldcutbuf"
}
zle -P bracketed-paste bracketed-paste _start_paste

And my pastes are appropriately highlit. (Wouldn't it really be more
useful to have the middle argument optional? I see how it might be
confusing if you're used to the zle -N behavior though.)

diff --git i/Src/Zle/zle_thingy.c w/Src/Zle/zle_thingy.c
index 8c66761..20a1de9 100644
--- i/Src/Zle/zle_thingy.c
+++ w/Src/Zle/zle_thingy.c
@@ -347,7 +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},
+       { 'P', bin_zle_prototype, 2, 3},
        { 'R', bin_zle_refresh, 0, -1 },
        { 'M', bin_zle_mesg, 1, 1 },
        { 'U', bin_zle_unget, 1, 1 },
@@ -596,6 +596,7 @@ bin_zle_prototype(char *name, char **args,
UNUSED(Options ops), UNUSED(char func
 {
     Thingy t;
     Widget w, pw;
+    char *funcname = args[2] ? args[2] : args[0];

     t = rthingy((args[1][0] == '.') ? args[1] : dyncat(".", args[1]));
     pw = t->widget;
@@ -618,9 +619,9 @@ bin_zle_prototype(char *name, char **args,
UNUSED(Options ops), UNUSED(char func
        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]);
+       w->u.comp.func = ztrdup(funcname);
     } else {
-       w->u.fnnam = ztrdup(args[2]);
+       w->u.fnnam = ztrdup(funcname);
     }
     if (bindwidget(w, rthingy(args[0]))) {
        freewidget(w);


-- 
Mikael Magnusson



Messages sorted by: Reverse Date, Date, Thread, Author