From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 23453 invoked from network); 24 Mar 2022 19:53:03 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 24 Mar 2022 19:53:03 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1648151583; b=rG1DkQFLJBmZmNyAJYiE/pgg9iK5oDcRK++c+crUBJpGbGM+bYoKHAimW6okWUtqEKL84DtoLU +G3C7dzy2drciR/5OswxZ/LwPITU5UD2DaKSMOLuSQNPLB8SITkeDpEU4nhnLPuPPnXBmd25mt 3QFRsXiuPn8dqe0KtTc0GLJ+dFujw2zoTsrjrqRXnX8ZPlMN9SSjuXk0OOTJfs+ZLWok+vY7gw Oz+63dD6dzCRu6cN94R11H0vh05fmJSjLxnF/lgI+9raBjfgy8bcXCBuIyoiGsDiAHjAkrDG7a wJ4LJP3ijJ2aAA0EI06aLQdf4ok6q8Awr7280mAeogDFcg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (smtpq2.tb.ukmail.iss.as9143.net) smtp.remote-ip=212.54.57.97; dkim=pass header.d=ntlworld.com header.s=meg.feb2017 header.a=rsa-sha256; dmarc=pass header.from=ntlworld.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1648151583; bh=1Sj5Am61OlwYUhOIUISgWs6QSj3OKHtswdbUu91jsxg=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:MIME-Version:Content-Type: References:In-Reply-To:Date:To:From:Subject:Message-ID:DKIM-Signature: DKIM-Signature; b=mH+tVWWKtOLcnDR4UkNjgIhwy/lLG1/ydo40rU71SJcNGYVyPKmAPKKEfjUphbd2dBQs8RL0CM bPGf/EQDT3Kx0apuZ1boLVodZGuEWIrLXyr5FCcoRU8cawMCwyB1x+oa0tiGaVs2/Sg7DKx2xY 0T3sBsTtuSi0rq3vqU73nNK3wri9jlDGYnasDgRarN0x007qUz+TItGs6vAD9p45gGP4e+wn5O YnXnADA3TByyLI9qAHGvSshkBZy0BcEjFSOqI9EwibL9F9Cri02dZCHtlh7tDROOsTuUKB4VdK Gyio41qDC7oZE5dItPlG0VauNXPX/MFPoBkU39KatQ3zHg==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: Mime-Version:Content-Type:References:In-Reply-To:Date:To:From:Subject: Message-ID:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=/vmUG3BLY0TdnSE0tEQPMd9AZGNyUbdnhq4Yz63dBDU=; b=hdQFrr3E9nRVx9yH/WGpirh3Oe gJNZk5JhMgyxdCG/znlYux/nJDU+uTKeyyoiVMjS31YbWI8s4gVgvtb8HAyaHkgaKD+TYxtJ3oAN/ KABzEK0ZJv5IknHEmI4pYbwzPNRyGc9LSZKIaI+rwkLsGBEG4+QlTA+A1VWzksdE+P45zyE6CykFQ tEdtk8j+2v72fKgZ+mXq0+m6M+e3HPguRLd21v1tFIHOeP9I97GEVebVQct+A5azxwLXRS0Bamlm1 VcTsFrrRFOOxzEHRRrBiOPfsySZQyC1LyAlCoQY47XnyUt6UJKXMpOc0KWMKIwX2OMoGQq4TBWO6E 1y6yvsOg==; Received: from authenticated user by zero.zsh.org with local id 1nXTW2-000CPT-N4; Thu, 24 Mar 2022 19:53:02 +0000 Authentication-Results: zsh.org; iprev=pass (smtpq2.tb.ukmail.iss.as9143.net) smtp.remote-ip=212.54.57.97; dkim=pass header.d=ntlworld.com header.s=meg.feb2017 header.a=rsa-sha256; dmarc=pass header.from=ntlworld.com; arc=none Received: from smtpq2.tb.ukmail.iss.as9143.net ([212.54.57.97]:45936) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1nXTVC-000Bfh-3n; Thu, 24 Mar 2022 19:52:10 +0000 Received: from [212.54.57.107] (helo=csmtp3.tb.ukmail.iss.as9143.net) by smtpq2.tb.ukmail.iss.as9143.net with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXTVB-0004yx-Io for zsh-users@zsh.org; Thu, 24 Mar 2022 20:52:09 +0100 Received: from pws-Zeus ([82.1.229.179]) by cmsmtp with ESMTPA id XTVBn9M96au4XXTVBn8684; Thu, 24 Mar 2022 20:52:09 +0100 X-SourceIP: 82.1.229.179 X-Authenticated-Sender: p.w.stephenson@ntlworld.com X-Spam: 0 X-Authority: v=2.4 cv=LOp1/ba9 c=1 sm=1 tr=0 ts=623ccbe9 cx=a_exe a=W4rGJ7PGCSRRUvufKHO8Dg==:117 a=W4rGJ7PGCSRRUvufKHO8Dg==:17 a=IkcTkHD0fZMA:10 a=o8Y5sQTvuykA:10 a=NLZqzBF-AAAA:8 a=3UcIABu_zMllX_ZkBoUA:9 a=QEXdDO2ut3YA:10 a=wW_WBVUImv98JQXhvVPZ:22 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ntlworld.com; s=meg.feb2017; t=1648151529; bh=/vmUG3BLY0TdnSE0tEQPMd9AZGNyUbdnhq4Yz63dBDU=; h=Subject:From:To:Date:In-Reply-To:References; b=Myo483QUejQojZwwGOA9q63kjyV+fWUPPvEjodSrtJq0L210M7HFH33XSp1c8PBBN 7FmihDT6K7MllRk1YrMOdgv50r74bYIJzKXSdEdku6F1MwDopQiB8Nm3DxVjtVxaeE qBvjM+RopLn+HnKN7x7xvZjhRLILRblLksdqLS03NkwIXS+25rJ9peMQb2k+ptWgCW dUkm+etEmvM0xKUaWUtink1gP2nTO66TRVFDnDA8w7bpEdTtfGUm9t+ug/LOhlRudg 1q5q0yBlchgAiOenkovjkTuZL95JaGkG7OIlRqIgMIbD3DAn3GJ2cg0O2Mda7iWWj2 pDFFI70D9zZUQ== Message-ID: Subject: Re: Load autoloadable function, but only in enclosing function scope From: Peter Stephenson To: zsh-users@zsh.org Date: Thu, 24 Mar 2022 19:52:08 +0000 In-Reply-To: References: <306931674.638268.1648141537809@mail2.virginmedia.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5-0ubuntu0.18.04.2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-CMAE-Envelope: MS4xfP7P4xal7Cl4gEBVpBwHgOFqsm5iAK4KAO9B+cfeQecbMQOowzZL3vz/rEcnIC+vD93IxCiWNH0NTIwZ6cHbt6lI9jF6ZA+o/G6zcP11jfIxGVfAz9S/ SVzNVZJS+bGyW64jYCewHtEywIci3ePekt3oTMbyLDMfJ5bumKoXpnxiOMbQHPAf1ccjmX3Pbwy5Ig== X-Seq: 27614 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: On Thu, 2022-03-24 at 10:51 -0700, Bart Schaefer wrote: > On Thu, Mar 24, 2022 at 10:06 AM Peter Stephenson > wrote: > > > > With that key limitation --- if you've already got functions with the > > names of the ones you're creating, you're stuffed --- you can automate > > it like this. > > > > fn() { > > local -a oldfuncs=(${(k)functions}) > > It actually can be even shorter than that, depending on how carefully > the context needs to be preserved. Peter's example keeps the > definitions of any functions that were previously defined, even if > those definitions were replaced (by autoload execution or explicit > redefinition). The example below restores all the function > definitions to their previous state, even when replaced. (Native zsh > mode semantics assumed below.) > > foo() { print original foo } > bar() { > local funcs=(${(kv)functions} > { > foo() { print the bar foo } > foo > } always { > functions=($funcs) > } > } > > This does have side-effects for autoloaded functions; they become > defined with "builtin autoload -X" as the body, which doesn't always > work the same way as a true autoload. It's got side effects for other fucntions, which is that that the line numbers recorded no longer match those in the file the function is autoloaded from (you don't see those unless you're using a debug prompt or equivalent). You're also at the mercy of zsh's ability to convert internal structures into text and back, which is supposed to work, though not particularly efficiently. pws