Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: function copy
- X-seq: zsh-workers 44549
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Peter Stephenson <p.stephenson@xxxxxxxxxxx>
- Subject: Re: PATCH: function copy
- Date: Tue, 16 Jul 2019 12:06:17 -0700
- Cc: "zsh-workers@xxxxxxx" <zsh-workers@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=OqleA8eK2Zn0aSLxkyeU93/XS6mIj0pRRlM1JGoWv2c=; b=oLWLDNv3b0wx8q6dx5Xg0kQHsGTAVxmONMBzSs1GWd1dy3SNtzwietk/6Ten2v8Ht/ AP6WP98kRYZUSQNOFOJHV5ZfdugFHZf3esDFfyUCYaIpvgn5uTj1PATBjrVDhY6krQF4 wJQwD4Zg4cEpVwVLg91fv5B0n2qc3fOGRqOjka4uzEJliGNw/OSf4yctUMgiWhrxgJr2 JF6KaX8zEAHEMlGCq5EpQLOmpddnw1KVqgZq5dcShg8IhXS97HBJ9I3ka1NX+bWd5KYg Q6PMZ287CFTODY+vrGC4D9T8Hzbjp8D6I4Y4efbE6m/3K/B1Qdr2hpy+jEuGl6FxvlEu Mu1Q==
- In-reply-to: <1563267373.6702.5.camel@samsung.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <b80d50af30a0e94f5335d3deeb2bd7d4594ba112.camel@ntlworld.com> <CGME20190715214328epcas2p153c44d86e62004db0d2bc67fc6ad5a66@epcas2p1.samsung.com> <CAH+w=7b=AaS1s6_v8hBp6gqrJvY4ST28-XW85+qvK2sqoBojDg@mail.gmail.com> <1563267373.6702.5.camel@samsung.com>
On Tue, Jul 16, 2019 at 1:56 AM Peter Stephenson
<p.stephenson@xxxxxxxxxxx> wrote:
>
> On Mon, 2019-07-15 at 14:42 -0700, Bart Schaefer wrote:
>
> > "around" you need a way to say "call the original function HERE" which
> > you can then embed in another function that becomes the "around" (and
> > which is called in place of the original everywhere except HERE).
>
> I think you're implying you'd rather not have an additional function
> name to deal with, i.e. the HERE is indicated in some other fashion.
> That's quite hard to fit into zsh syntax.
There doesn't need to be any special syntax, just some special name
linking, e.g.:
_my_fn() {
# do stuff here
_orig_fn "$@"
# do stuff here
}
advice-around _std_fn _my_fn _orig_fn
advice-around _other_fn _my_fn _orig_fn
and "advice-around" would arrange that any time either _std_fn or
_other_fn was called, the name _orig_fn would temporary be linked to
either _std_fn or _other_fn (as appropriate to whichever one was being
replaced), and then _my_fn would be invoked. At the end of _my_fn the
temporary name _orig_fn would evaporate. This allows the same advice
to be linked to multiple functions without having to copy all of them,
etc.
For ordinary functions this is the same as doing something like
_my_fn() {
local _orig_fn=$1
shift
# do stuff here
$_orig_fn "$@"
#do stuff here
}
alias _std_fn="_my_fn _std_fn"
alias _other_fn="_my_fn _other_fn"
except you don't have to worry about whether aliases are going to
expand or what order to define them or having the extra argument to
shift off, etc. For widget functions, though, there's a lot more to
do to be able to invoke a widget properly in the middle of _my_fn,
especially if the original widget is a builtin.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author