From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id f1a584e3 for ; Tue, 16 Jul 2019 16:56:41 +0000 (UTC) Received: (qmail 1709 invoked by alias); 16 Jul 2019 16:56:33 -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: List-Unsubscribe: X-Seq: 44548 Received: (qmail 25 invoked by uid 1010); 16 Jul 2019 16:56:33 -0000 X-Qmail-Scanner-Diagnostics: from granite.fifsource.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.101.2/25510. spamassassin: 3.4.2. Clear:RC:0(173.255.216.206):SA:0(-1.9/5.0):. Processed in 1.525497 secs); 16 Jul 2019 16:56:33 -0000 X-Envelope-From: phil@fifi.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at fifi.org designates 173.255.216.206 as permitted sender) Message-ID: <11a8ebbdbe63f0c6303ab53deeffd17e9ae168a5.camel@fifi.org> Subject: Re: PATCH: function copy From: Philippe Troin To: zsh-workers@zsh.org Date: Tue, 16 Jul 2019 09:55:56 -0700 In-Reply-To: <1563267373.6702.5.camel@samsung.com> References: <1563267373.6702.5.camel@samsung.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.32.3 (3.32.3-1.fc30) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit On Tue, 2019-07-16 at 09:56 +0100, Peter Stephenson wrote: > On Mon, 2019-07-15 at 14:42 -0700, Bart Schaefer wrote: > > On Mon, Jul 15, 2019 at 1:00 PM Peter Stephenson > > wrote: > > > > > > > > > I've had this lying around for a while, wondering if there's more > > > to it, > > > but I can't think of it. > > > > > > The point is that it's very easy internally to provide an > > > interface to > > > tweak standard functions to add arbitrary code before and after > > > --- we > > > have most of the support for this internally, and just lack the > > > means to > > > add a different name for a function, which this adds. > > Emacs calls this "advice" and allows before/around/after variations > > which can be added without having to redefine the existing > > function. > > I have a half-finished (that may be optimistic) module to provide > > this > > for ZLE widgets. Handling the before/after is not too bad, but for > > "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). > > That's basically what I showed in my example. > > functions -c _std_fn _my_fn > _std_fn() { > # do stuff here > _my_fn "$@" > # do stuff here > } I've been using the following hackish idioms: % foo() { print foo $@; } % () { local func=$functions[foo] eval "foo() { print before foo; { $func }; print after foo }" } % foo bar before foo foo bar after foo and % functions[foo_copy]=$functions[foo] Of course these cause reparsing of the function body, so "function -c" may still make sense. I like the idea of a full advising system. Phil.