From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10249 invoked by alias); 29 Sep 2016 07:09:56 -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: X-Seq: 39490 Received: (qmail 27257 invoked from network); 29 Sep 2016 07:09:56 -0000 X-Qmail-Scanner-Diagnostics: from mail-pa0-f43.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.220.43):SA:0(0.0/5.0):. Processed in 0.618972 secs); 29 Sep 2016 07:09:56 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at brasslantern.com does not designate permitted sender hosts) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=PzoF9kLoW6m9njshIOJcHfWASB0VpLKo4gGmhLLzkVE=; b=IGBoOkvcFELafZPNbvGMwTrh/VG/7DZFLLwsffGF0rewrnVxGl1yijjrVZJ1mr/hxC Jjti7x7FUyp/zdmBqrCJWIpIawpul4aVIFNFJ9TWWEBjr0wB5/AzZiM4WpjkhrN0v33T ILWQ2LywJaIvg0jdAupkrwSAsb+ELrxzu0+2DdyIhfTp6K3vW7C38jSg++VSNZh7IbKP EenND2Kwx47CnSaFf/vdEBhGjTAagizYYEs6CDEuWnUkGHb8DD4ICtK5cELURvmxwX4u VPQKPsV1qGC7zjjZ8xZMdW5WTzrzkTGopYtpdjh29FugMIwE/fjHY4dDk9UuRigh2CLx a8xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version; bh=PzoF9kLoW6m9njshIOJcHfWASB0VpLKo4gGmhLLzkVE=; b=E3xIryF6ZiBQxspFJKrjIADWlAQlJromO5ebHtJ9i53r5GLFzpePaYywBqUgfhhwF1 b3EuOUsKeE1s5usZaYRWJl3n7uWc8Ccp39BWnnLX7fmwRoXHhaYYqK/SutYUFmXIsOtP w0ewKLvVvcSME41wDWxGgSR2okcm8L5C+Dhza5mAdhgys+f+KXNenea9QOayvERtxcOa MndDOw9CUsNTuTx8ynvgHf9cs2MLYiycx0HtkZr/egXeLfJ3xtNMrOXaiR4FjZJe0kgn /2L6BYE1navVszOYmDvsE46OgQs02i95ztzHPlf6+TLcEvcSZOVjADiOPK4pg0DhTwYX Bx2w== X-Gm-Message-State: AE9vXwPcc/BjqcZNtAvCCd2g7Q/vCEtsZcT9lln5VMMRvvg0Yr7eOW3MLKCvGSlrlzH1Pw== X-Received: by 10.66.48.8 with SMTP id h8mr63462608pan.92.1475132987660; Thu, 29 Sep 2016 00:09:47 -0700 (PDT) From: Bart Schaefer Message-Id: <160929001004.ZM27686@torch.brasslantern.com> Date: Thu, 29 Sep 2016 00:10:04 -0700 In-Reply-To: Comments: In reply to Sebastian Gniazdowski "Surprising effect of fun() { local FPATH=...; autoload -X }, and a bug" (Sep 27, 12:07am) References: X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: Zsh hackers list Subject: Re: Surprising effect of fun() { local FPATH=...; autoload -X }, and a bug MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Sep 27, 12:07am, Sebastian Gniazdowski wrote: } } eval "function $func { } local FPATH="$PLUGIN_DIR":"${FPATH}" } builtin autoload -X ${opts[*]} } }" } } What I astonishingly realized today is that functions autoloaded this } way can further use autoload builtin purely normally. FPATH visible } from the specially-autoloaded function is modified, has the required } added component, and builtin autoload works as expected (even with } <5.1 Zsh, it has a more specific manual autoload stub). This will be the case as long as the autoload command AND the first run of the normally-autoloaded function BOTH happen during the FIRST run of the "specially-loaded" function. E.g. suppose we have this silly example: --8<-- file "outer" --8<-- if (( $+functions[inner2] )); then inner2 else autoload inner1 inner2 inner1 fi -->8-- file "outer" -->8-- and we send func=outer through your eval above. When "outer" is first run, the call stack will look like outer # scope of local FPATH is here autoload -X outer # "normal autoloads" are here inner1 # modified FPATH is still in scope In this case inner1 will load with the modified FPATH. On the second and subsequent runs of "outer", the call stack will look like: outer # no FPATH declared inner2 # no modified FPATH in scope thus inner2 will load from the normal fpath. It's the fpath at time of function call that matters, not the fpath at time of autoload command.