Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Surprising effect of fun() { local FPATH=...; autoload -X }, and a bug
- X-seq: zsh-workers 39490
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: Surprising effect of fun() { local FPATH=...; autoload -X }, and a bug
- Date: Thu, 29 Sep 2016 00:10:04 -0700
- 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==
- In-reply-to: <CAKc7PVCXq6jQe2gF-Hb4UFBx7UXxRE=3_8Z2Oyq-H6d0LoNLAA@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CAKc7PVCXq6jQe2gF-Hb4UFBx7UXxRE=3_8Z2Oyq-H6d0LoNLAA@mail.gmail.com>
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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author