zsh-workers
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: zsh workers <zsh-workers@zsh.org>
Subject: Re: PATCH: Set completion function flags correctly for zle -P
Date: Mon, 31 Aug 2015 12:17:21 +0200	[thread overview]
Message-ID: <CAHYJk3S40XYr=pzTnLOjpGmUYa2=x4zfutS4h73ieSr5HScQWQ@mail.gmail.com> (raw)
In-Reply-To: <1441014958-27075-1-git-send-email-mikachu@gmail.com>

On Mon, Aug 31, 2015 at 11:55 AM, Mikael Magnusson <mikachu@gmail.com> 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


  reply	other threads:[~2015-08-31 10:17 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-30 21:59 Overriding a yank* widget in zle Wayne Davison
2010-12-31  6:39 ` Wayne Davison
2010-12-31  8:28 ` Bart Schaefer
2010-12-31 23:23   ` Wayne Davison
2015-08-31  7:54   ` PATCH: Implement zle -P Mikael Magnusson
2015-08-31  7:56     ` Mikael Magnusson
2015-08-31  9:55     ` PATCH: Set completion function flags correctly for " Mikael Magnusson
2015-08-31 10:17       ` Mikael Magnusson [this message]
2015-08-31 17:11     ` PATCH: Implement " Peter Stephenson
2015-09-01  6:23       ` Bart Schaefer
2015-09-01  6:50         ` Mikael Magnusson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHYJk3S40XYr=pzTnLOjpGmUYa2=x4zfutS4h73ieSr5HScQWQ@mail.gmail.com' \
    --to=mikachu@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).