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.1 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 a9fe7c41 for ; Tue, 16 Jul 2019 08:57:02 +0000 (UTC) Received: (qmail 9733 invoked by alias); 16 Jul 2019 08:56:55 -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: 44545 Received: (qmail 7542 invoked by uid 1010); 16 Jul 2019 08:56:55 -0000 X-Qmail-Scanner-Diagnostics: from mailout2.w1.samsung.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(210.118.77.12):SA:0(-7.0/5.0):. Processed in 3.494176 secs); 16 Jul 2019 08:56:55 -0000 X-Envelope-From: p.stephenson@samsung.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.samsung.com designates 210.118.77.12 as permitted sender) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20190716085616euoutp0223ee2e931f8336b83726d584125328bc~x12V2WeUr1852518525euoutp02B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1563267376; bh=L+KB/wvH4JUVDBAQ1bhZG/BUs/QnJxLh+IiOjjY+54Y=; h=Subject:From:To:Date:In-Reply-To:References:From; b=WKarnpzbabt1V4hP0NGl852GwIbafkkuzP3DJHcqf9FGnZi2QQKBlJOwLjeG+E91n S9TIJiG3IcLMLxm7XMddfWrirtbli6a5g8SkXtvDflE4oLfUvt5tdP9rIWG65e1LuZ cBqHZKduXVOmILGqP8HWGS/hkNZuZe2U7MyZ2oMQ= X-AuditID: cbfec7f2-f2dff700000010ca-f2-5d2d912f05e8 Message-ID: <1563267373.6702.5.camel@samsung.com> Subject: Re: PATCH: function copy From: Peter Stephenson To: Date: Tue, 16 Jul 2019 09:56:13 +0100 In-Reply-To: X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrHIsWRmVeSWpSXmKPExsWy7djPc7r6E3VjDTpPKlocbH7I5MDoserg B6YAxigum5TUnMyy1CJ9uwSujA2XbrMUTOWvmPhuC1sDYydPFyMnh4SAicSn3wdZuxi5OIQE VjBKrLnSzwqSEBLoY5Lo+SECkehlknj45hsLTMeGn7ugOpYzSlx6fZcVrurJpmVQzhlGicfb t0I5Fxglmq5vYAbp5xUwlLh5vwXMFhZQlOg7cBJsLhtQfOqm2YwgtoiApMS15tNgNouAqsTb le+Bajg4OAUCJS59D4E4Q0Niw81jTBAjBSVOznwCNoZZQF6ieetsZpC9EgL32SSOXWlng2hw kXi+5j0zhC0s8er4FnYIW0bi9OQeFoiGdmAITHrNDuH0MEpsOnqHEaLKWqLv9kVGkCuYBTQl 1u/Shwg7SnzZtoQdJCwhwCdx460gxBF8EpO2TWeGCPNKdLQJQVSrSexo2soIEZaReLpGYQKj 0iwkH8xC8sEshFULGJlXMYqnlhbnpqcWG+allusVJ+YWl+al6yXn525iBKaC0/+Of9rB+PVS 0iFGAQ5GJR7eE3t0YoVYE8uKK3MPMUpwMCuJ8Np+1Y4V4k1JrKxKLcqPLyrNSS0+xCjNwaIk zlvN8CBaSCA9sSQ1OzW1ILUIJsvEwSnVwFjzz1vR85DcsorEJUfnfXl6gJPBz/xGOHfpq+Vn XnsqXGfjYrvsseTF2YgqbreVjYWrFNOWOU75tjh3VbTTAZtVd99qH3Kb/d1n8tv7Wh7yWVIf /6677CnPzTRLYotVQXv6bE9ut4+GC40Ov22Y6brZ9ey6iNx5/lMEf8Z/uvX15+lLnNP0pfco sRRnJBpqMRcVJwIAe/oXgAEDAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpkkeLIzCtJLcpLzFFi42I5/e/4PV29ibqxBtNX6locbH7I5MDoserg B6YAxig9m6L80pJUhYz84hJbpWhDCyM9Q0sLPSMTSz1DY/NYKyNTJX07m5TUnMyy1CJ9uwS9 jA2XbrMUTOWvmPhuC1sDYydPFyMnh4SAicSGn7tYuxi5OIQEljJKPNs2kQUiISPx6cpHdghb WOLPtS42iKJuJolPC1uZQBJCAmcYJdreK0EkLjBKbL2yBizBK2AocfN+CzOILSygKNF34CTY VDag+NRNsxlBbBEBSYlrzafBbBYBVYm3K98D1XBwcAoESlz6HgIx8xmjxLdDT8B6mQU0JVq3 /4a6SENiw81jULsEJU7OhKmRl2jeOpt5AqPQLCQts5CUzUJStoCReRWjSGppcW56brGRXnFi bnFpXrpecn7uJkZg8G879nPLDsaud8GHGAU4GJV4eE/s0YkVYk0sK67MPcQowcGsJMJr+1U7 Vog3JbGyKrUoP76oNCe1+BCjKdBDE5mlRJPzgZGZVxJvaGpobmFpaG5sbmxmoSTO2yFwMEZI ID2xJDU7NbUgtQimj4mDU6qBcacm+wO+YM36zc4Vk74ZhvI5fe73dl5onnP43IkjEd6Hsrat YtgS6ltwaEpDQruZxeSO6IzywF9dzAtOfuo9dbxAyUTa/Tmr5lG/yBKNGf96vhtKpi7nOLog 4MWic+8iX8UdPb48uujWHq8e/e7Xl/YzKYtVF+xsqPj18NXvZRedf5cs3vyUS4mlOCPRUIu5 qDgRAGAVbZKUAgAA X-CMS-MailID: 20190716085615eucas1p2b2f4355d23909a45276d8883224af65b X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20190715214328epcas2p153c44d86e62004db0d2bc67fc6ad5a66 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20190715214328epcas2p153c44d86e62004db0d2bc67fc6ad5a66 References: 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 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. > The other thing that would be really helpful in order to do it "your > way" would be local functions, so that when the calling context exits, > _std_fn reverts to its old definition and _my_fn disappears.  Hacking > this by making the entire $functions array local is error-prone. That's another feature that's also quite bug-prone to implement --- we've had a zillion problems just with local variables which have been there for ages --- but at least if it's internal it's just a single implementation. pws