zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: zle hook conventions (was Re: bracket-paste-magic ...)
Date: Fri, 3 Jun 2016 15:51:54 -0700	[thread overview]
Message-ID: <160603155154.ZM25057@torch.brasslantern.com> (raw)
In-Reply-To: <20160603204043.GA18181@tarsus.local2>

On Jun 3,  8:40pm, Daniel Shahaf wrote:
}
} I think it is possible for a plugin to hook into zle without interfering
} with other plugins' hooks, without assuming anything about those other
} plugins.  z-sy-h's hooking code attempts to achieve that

Yes, but (a) it's convoluted (b) it doesn't solve the ordering problem
[whichever plugin is sourced last gets its wrapper outermost] (c) it
is fragile in cases such as reloading a plugin [load A, load B, then
load A again, and now you have A() { B() { A() { ... } } } wrapping].

Plus, I thought the whole point of this conversation was to consider
ways to avoid having to do that kind of thing, because most plugins
are a lot more naive than z-sy-h.

} I think you're saying: if one plugin uses add-zle-hook-widget(), then
} other plugins can coexist with that plugin by also using
} add-zle-hook-widget().

Again yes, but also: if no plugin uses add-zle-hook-widget because it
requires zsh-5.X for some X >=3 and those plugins want to keep working
in zsh-4+, then we might as well never have introduced the feature.
If we're taking the position that the feature is useful, we should
design it in such a way that plugin writers want to adopt it.

} I'm a bit wary of imposing dependencies on other plugins.  Might there
} be a valid reason for those fourth-party plugins to prefer not to use
} add-zle-hook-widget?

You seem to be arguing in circles here.  This is back to supporting the
position of throwing up our hands and doing nothing because we can't
(or shouldn't) make everyone do the same thing.

Plugins that don't want to use the convention are in no different boat
than they always were:  They either must be clever like z-sy-h, or they
simply break (or cause breakage) by being naive, and it's then up to
the user who's installing them to work it out (which was my original
point about paying attention to ~/.zshrc when updating a plugin).

} > Usage would be e.g. (inventing a function for example purposes):
} > 
} >     add-zle-hook-widget zle-line-pre-redraw 30:z-sy-h-redraw
} 
} This appears to be a straightforward registrar API.

Intentionally comparable to add-zsh-hook.
 
} I would suggest making this idempotent by uniquifying the list of hooks
} (in order to support 'source ~/.zshrc').

Cf. "crudely sketched", but it in fact does so, the extant_hooks local
is declared with -U, so when assigned it will discard duplicates.

} With my plugin author perspective, if I were to add a dependency on this
} function, I'd want it to be easily available for users to install.
} Where would add-zle-hook-widget's implementation live?  In Functions/ in
} the zsh tree, or as a third-party project?

I'd presume that if the convention were agreed upon, we'd ship it with
the "standard" set of autoloadable functions alongside (or even packed
with, in some way) add-zsh-hook.

} > 	zstyle -g extant_hooks "$hook" widgets
} > 	extant_hooks+=("$@")
} > 	zstyle -- "$hook" widgets "${extant_hooks[@]}"
} 
} Why use zstyle's instead of declaring a global array and appending to it?

Mostly to be able to use the widget names directly without having to
remove hyphens or convert to underscores.  Partly, to avoid polluting
the parameter namespace further.  Also to demonstrate that zstyle is
not just a quaint side-effect of the completion system.

-- 
Barton E. Schaefer


  reply	other threads:[~2016-06-03 22:51 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-06 20:53 bracket-paste-magic adds backslashes inside a quoted string if URL is pasted ("regression" compared to pre-5.1 url-quote-magic) Axel Beckert
2016-05-08 18:50 ` Bart Schaefer
2016-05-09 14:13   ` Vincent Lefevre
2016-05-09 15:41     ` Bart Schaefer
2016-05-10  8:58       ` Vincent Lefevre
2016-05-10 19:58         ` Bart Schaefer
2016-05-13  9:23           ` Vincent Lefevre
2016-05-13 11:06             ` Bart Schaefer
2016-05-13 12:19               ` Vincent Lefevre
2016-06-02  7:20                 ` undo problems/crashes (was Re: bracket-paste-magic ...) Bart Schaefer
2016-05-13 22:20               ` bracket-paste-magic adds backslashes inside a quoted string if URL is pasted ("regression" compared to pre-5.1 url-quote-magic) Daniel Shahaf
2016-05-14  1:33                 ` Mikael Magnusson
2016-05-14  3:00                   ` Daniel Shahaf
2016-05-15 11:59                     ` Bart Schaefer
2016-05-19 21:14                       ` Daniel Shahaf
2016-06-02  7:06                         ` zle hook conventions (was Re: bracket-paste-magic ...) Bart Schaefer
2016-06-03 20:40                           ` Daniel Shahaf
2016-06-03 22:51                             ` Bart Schaefer [this message]
2016-06-04 16:57                               ` Daniel Shahaf
2016-06-10 17:36                           ` Daniel Shahaf
2016-06-10 19:51                             ` Bart Schaefer

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=160603155154.ZM25057@torch.brasslantern.com \
    --to=schaefer@brasslantern.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).