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=DKIM_SIGNED,DKIM_VALID, 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 a5680973 for ; Tue, 16 Jul 2019 19:07:18 +0000 (UTC) Received: (qmail 28865 invoked by alias); 16 Jul 2019 19:07:10 -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: 44549 Received: (qmail 11823 invoked by uid 1010); 16 Jul 2019 19:07:10 -0000 X-Qmail-Scanner-Diagnostics: from mail-lj1-f174.google.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(209.85.208.174):SA:0(-1.9/5.0):. Processed in 4.022113 secs); 16 Jul 2019 19:07:10 -0000 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.208.174 as permitted sender) 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== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=OqleA8eK2Zn0aSLxkyeU93/XS6mIj0pRRlM1JGoWv2c=; b=bChqCrx2uC8avDAZ91euUlFhCIQIOcNwDUIcfp3E0I04A3JY7Rai2wmClqoc5n+eJr FtPDmOxdvAowmErit6xcM6Gu7ZSR5PQ7H9M7nl773zlj4jIBq5Mw3LSsydhsG1H2EI5U zX7Slz2ZpzL9iLrondhfo2egufKMxhVxNln9iHp2yRV0s9qqp79+uqcEWZnHxICGctsg aFBKneQ/t2jt5pr/582zn/DYwqWQrEi6aUn1yqNoGp39ObhtgZ2cFeZaJlv0EDj6F3Fv 6blftNnmn4sPeOx2lpwsmyRgicdWER2VTEOYFzfOd+0kQLnoOn4KOGcnHuNDwoWXRrJZ r3xw== X-Gm-Message-State: APjAAAUbZeK4bgocjU1MDqb0Sroh3mzpW+DBQl+ccf20iwuMPgjiM2/Z G7QrKxU6sqPsATHkurk6t3Ceg6kUs4+K1hUUEKf4nwWK X-Google-Smtp-Source: APXvYqytcd+x8G0ucLS4EgmjpplvYSy0mmrYCjCSxjuPTF0Lt++Mr22xKF/oKgwUN0eeoI4ceqMr2LjbW6K0dR2LFQk= X-Received: by 2002:a05:651c:1b8:: with SMTP id c24mr19129746ljn.2.1563303990585; Tue, 16 Jul 2019 12:06:30 -0700 (PDT) MIME-Version: 1.0 References: <1563267373.6702.5.camel@samsung.com> In-Reply-To: <1563267373.6702.5.camel@samsung.com> From: Bart Schaefer Date: Tue, 16 Jul 2019 12:06:17 -0700 Message-ID: Subject: Re: PATCH: function copy To: Peter Stephenson Cc: "zsh-workers@zsh.org" Content-Type: text/plain; charset="UTF-8" On Tue, Jul 16, 2019 at 1:56 AM Peter Stephenson 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.