From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2141 invoked by alias); 2 Jun 2016 07:06:09 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 38569 Received: (qmail 1139 invoked from network); 2 Jun 2016 07:06:07 -0000 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=o+K4bz0hw+3XobaI7NTRWuYrNZlb6KwRoq+mbjRINfg=; b=p5woCUua2Ld/K2xIegAjtJVIc5sNiKVgisLkJITYk9qTtwvEWQxEvdDGv/tR+R3/xU 6tylB8SQPIJYxmWgo7iWCoN5tY6/H2xTqYrY7/afvH3ei/6pOKYhpL0i24d6Zu1hFRyV 6NWR3Zdpg8BamM2Am1Yo2f12YSa59ObtknmmCLCZKzyPBF22iYZETZGUJjXLxTrXvuIg dUUTSSsYJ2+kxuUEVR2SrJnkBJ5gRKC8XLknDZI64Hd68Xh87M8N6BhO5SeEfvMQZ2Lc /k6ScGrRWv+u9F0+75JELZBKchaXmdwcZXnxI76S7/KX8lggiGOtMSMSvgjBi9qI3rur ObXA== 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=o+K4bz0hw+3XobaI7NTRWuYrNZlb6KwRoq+mbjRINfg=; b=HQMWQLDTuGHjwZzTQX0NHiu0V99p5LZTxQEZTp05mVofJen80kc20Uvfq2kS8OdUZb HbEVTLgNh3ApzeQeqfmDS44imKv9twiQyn9nnRxL8LI4CUT10+SREp043clUN4JMu9gP bvlkOtql8AIuvc9Ds0vG7okopf7BRyp75WPi6tibzP0sRHbTYjqb0u5jyw4RU853hm+Q cCkHL8PNcZbcItQMXS5VeritSAjMU0AiBDBbPFhxOcx+urqsC1uk0WUbXX9GouP+TxtG fJuC3fvrHy4cpyO35cICAIFhCSyHOxKn3qJVJqjMME4mmq7FnEWS9kmQ2yTuL2PTGHbb ohng== X-Gm-Message-State: ALyK8tJ+aBfIlechvC4p7seykVkOQK0kFkRjy/2V2gjj/DwM793VOTh9yCQXeNJLdYa6Tw== X-Received: by 10.98.75.83 with SMTP id y80mr1654847pfa.97.1464851163151; Thu, 02 Jun 2016 00:06:03 -0700 (PDT) From: Bart Schaefer Message-Id: <160602000600.ZM14708@torch.brasslantern.com> Date: Thu, 2 Jun 2016 00:06:00 -0700 In-Reply-To: <20160519211458.GD8007@tarsus.local2> Comments: In reply to Daniel Shahaf "Re: bracket-paste-magic adds backslashes inside a quoted string if URL is pasted ("regression" compared to pre-5.1 url-quote-magic)" (May 19, 9:14pm) References: <20160509141306.GA18211@cventin.lip.ens-lyon.fr> <160509084143.ZM13554@torch.brasslantern.com> <20160510085833.GA20332@cventin.lip.ens-lyon.fr> <160510125848.ZM1686@torch.brasslantern.com> <20160513092348.GB18186@zira.vinc17.org> <20160513222039.GA2425@tarsus.local2> <20160514030031.GA2530@tarsus.local2> <20160519211458.GD8007@tarsus.local2> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: Zsh hackers list Subject: zle hook conventions (was Re: bracket-paste-magic ...) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On May 19, 9:14pm, Daniel Shahaf wrote: } } Bart Schaefer wrote on Sun, May 15, 2016 at 04:59:27 -0700: } > Hence I also think that a plugin registry for the special zle hook } > widgets ought to be implemented externally, and the plugins agree to } > make use of it -- because if the plugins don't follow such a } > convention then the user has to update .zshrc in lockstep with the } > plugin installation anyway. } } I don't follow your reasoning: whether .zshrc needs to be updated } manually is orthogonal to how the plugin hooks into zle. If you have two or more plugins referenced from .zshrc, and not all of them follow the same convention for how to hook into zle, then any time one of them changes the user has to make sure it hasn't now interfered with the hooks of the others. } It is about the mechanism used by zsh to find and run the code that } _installs_ the zle hook, not about whether said installation is done } by [...] That's exactly my point: A convention no one uses is no better than no convention at all, even if there's specialty C code instead of shell code. Further, an externally-defined convention can be made backward-compatible to at least some older versions of zsh. } I'm happy to keep this external, although if widgets shipped with zsh } used this "external" plugin, it'd probably become de facto official. Currently there aren't any functions shipped with zsh that would need this. The only references to the zle-* hooks in the shipped code are tests for whether zle-line-init is currently in progress, not for using any hooks to set up specific behavior. Crudely sketched, I'm thinking of something like this: zmodload zsh/parameter || { print -u2 "Need parameter module for zle hooks" return 1 } for hook in isearch-exit isearch-update \ line-pre-redraw line-init line-finish \ history-line-set keymap-select do function zle-$hook { local -a hook_functions hook_widgets local hook # Values of these styles look like number:name # and we run them in number order # $funcstack is more reliable than $0 # Also, ksh_arrays is annoying emulate zsh -c ' zstyle -a $funcstack[2] functions hook_functions zstyle -a $funcstack[2] widgets hook_widgets ' for hook in "${(@)${(@on)hook_functions}#*:}" do "$hook" || return done for hook in "${@${(@on)hook_widgets}#*:}" do zle "$hook" -Nw || return done return 0 } done # This stuff with "is it a function or is it a widget?" is # another reason we didn't define internal arrays for this. # Maybe just require widgets, and discard the functions bit. add-zle-hook-function() { local -aU extant_hooks local hook="$1" shift zstyle -g extant_hooks "$hook" functions extant_hooks+=("$@") zstyle -- "$hook" functions "${extant_hooks[@]}" if [[ -z "${widgets[$hook]}" ]]; then zle -N $hook fi } add-zle-hook-widget() { local -aU extant_hooks local hook="$1" shift zstyle -g extant_hooks "$hook" widgets extant_hooks+=("$@") zstyle -- "$hook" widgets "${extant_hooks[@]}" if [[ -z "${widgets[$hook]}" ]]; then zle -N $hook fi } Usage would be e.g. (inventing a function for example purposes): add-zle-hook-widget zle-line-pre-redraw 30:z-sy-h-redraw If you leave out the number: prefix, it's assumed you don't care in what order it executes, but it'll always be after the ones that do have number prefixes. Left up to the plugins to work out what number they need/get. Note you can call the same widget more than once by adding it with two different numbers.