Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATH: autoload with explicit path



On Fri, 27 Jan 2017 07:12:59 -0800
Sebastian Gniazdowski <psprint2@xxxxxxxxxxxx> wrote:
> I do the non-fpath autoloading by local FPATH parameter. There's
> drawback: if autoloaded function does further autoloading of other
> function, then the earlier supplied local FPATH parameter isn't active
> anymore.
> 
> So it's not possible to have /home/user/functions/{fun1,fun2}, autoload
> fun1, and have fun2 available for fun1. Now, with the new feature,
> directory path can be attached to function and if it calls autoload
> itself, then the attached directory can be examined before FPATH.

You're worried about something like this?


# set up function
local path_that_only_appears_here=/foo/bar
autoload -Uz $path_that_only_appears_here/fun1


# definition of fun1
autoload -Uz <what-goes-here?>/fun2
fun2


You can already do this using funcsourcetrace from zsh/parameter:
${funcsourcetrace[1]%%:<->} is the source file for the immediately
enclosing scope, so take the directory part of that and you've
got what you want (being careful if you happen to have evals
or anonymous functions which generate their own scopes).

It's a bit limiting you can't get that information for any function,
since it's alrady available internally in the shfunc structure.  I'd be
happy to add an associative array in zsh/parameter parallel to
$functions, say $function_sources, that gives the information for all
functions.

pws



Messages sorted by: Reverse Date, Date, Thread, Author