Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID
	autolearn=ham autolearn_force=no version=3.4.1
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=brasslantern-com.20150623.gappssmtp.com; s=20150623;
        h=from:message-id:date:in-reply-to:comments:references:to:subject
         :mime-version;
        bh=UufBRhHPmDTy8UHRDUdmg5oyc93zh6Fb0z3qHUF4ISQ=;
        b=V4jb2GvhYNdn64R1NHQfW8ci7u6oY9RG+7hygw5YUgd4JG8vB8/ED3CmrYB+W61u79
         EOlUb1eBGbMq1yElsS6rZqsZfG20vO3ODwJEXFh1MpWOBUWkKBO38lpiGwA3kB64yLBr
         2MNUefTrhJ+LDpfBEHQPHZeV1Vo3tTl4G3B41RjlRezdSk4asHZulpF0y9/nsESD9631
         zpijrtxzep9eG2+rJ+Ly/lFJlERpKml/sgwNhmI0GOkvErAhixrwl8CesxusHZRdyoGS
         9nBQz6zZfM60rnLT+phtvm44bA/SLNTOTcNWUbBYJ1r4p4cUCyxiLmhMQbYLMxeasUD0
         yvOg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:message-id:date:in-reply-to:comments
         :references:to:subject:mime-version;
        bh=UufBRhHPmDTy8UHRDUdmg5oyc93zh6Fb0z3qHUF4ISQ=;
        b=D0yQWFPKiF3ZMeaKR8oPEV3bq2nFfC9zOdYYNa6CP4rK27ZWWcExt0AiCHgtqiZxr0
         GAabAIfb4UHtpF9XZNJVuy7dDOds0WArmz0HWa2jb+/ojpkJkSC/RkwUehT7TMPYkbeZ
         M+qqtmZFIaQM5w9k4VlLOaCuW5qEu9K/PqaHinBeSrvGOer9zcfLDsweiUyYe0EGhHUA
         uE2/XpmUWdmPZWFlDMebRSkcVJHyYf+kWL0PQd4hw6sFg2hvUKijrudURZkD3jxhyOM+
         UppgVFgoOv1Yh3rFQOfcor39G46784199fvnwUn4vFolyICHlDw3gT7uFD4v1ZROHu0x
         hALg==
X-Gm-Message-State: ALyK8tJ2xTtfsOW3Zs9yi+w27GL9+XhX32KMBbOgKpP0LPOjy0k9Zu76FhUsCde4KLCxKw==
X-Received: by 10.66.78.166 with SMTP id c6mr30765978pax.37.1466549857841;
        Tue, 21 Jun 2016 15:57:37 -0700 (PDT)
From: Bart Schaefer <schaefer@brasslantern.com>
Message-Id: <160621155811.ZM9407@torch.brasslantern.com>
Date: Tue, 21 Jun 2016 15:58:11 -0700
In-Reply-To: <20160621014131.GB17100@tarsus.local2>
Comments: In reply to Daniel Shahaf <d.s@daniel.shahaf.name>
        "Re: [PATCH] add-zle-hook-widget" (Jun 21,  1:41am)
References: <160612184453.ZM11316@torch.brasslantern.com> 
	<20160613085219.GA23148@tarsus.local2> 
	<160614111054.ZM17893@torch.brasslantern.com> 
	<20160615232447.GA29225@tarsus.local2> 
	<160616222055.ZM27034@torch.brasslantern.com> 
	<160618162558.ZM5244@torch.brasslantern.com> 
	<20160621014131.GB17100@tarsus.local2>
X-Mailer: OpenZMail Classic (0.9.2 24April2005)
To: zsh-workers@zsh.org
Subject: Re: [PATCH] add-zle-hook-widget
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Seq: zsh-workers 38741

On Jun 21,  1:41am, Daniel Shahaf wrote:
} Subject: Re: [PATCH] add-zle-hook-widget
}
} Bart Schaefer wrote on Sat, Jun 18, 2016 at 16:25:58 -0700:
} >  for hook in $hooktypes
} >  do
} > +  # Check for an existing widget, add it as the first hook
} > +  if [[ ${widgets[$hook]} = user:* ]]; then
} > +      zle -A "$hook" "${widgets[$hook]}"
} > +      zstyle -- "$hook" widgets 0:"${widgets[$hook]}"
} 
} The last parameter expansion should strip the "user:" prefix.

No, it shouldn't, because the "zle -A" command creates a new widget
whose name begins with "user:".

This way if you run "add-zle-hook-widget -L" it will show you that the
widget with index zero was the user's previously defined widget.

Yes, this breaks things if the user's widget compares itself to $WIDGET
but there's no way around that [*] because the newly created hook is
the only widget allowed to use the reserved hook-widget name.

[*] A possible fix for this is to omit the -w when calling the widget
from zle, so that $WIDGET remains the hook-widget.  That would look
something like

      for hook in "${(@)${(@on)hook_widgets[@]}#<->:}"; do
          if [[ "$hook" = user:* ]]; then
              # Do not change $WIDGET, it may be tested in $hook
              zle "$hook" -N "$@" || return
          else
              zle "$hook" -Nw "$@" || return
          fi
      done

