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

Re: PATH: autoload with explicit path

On Mon, 12 Dec 2016 08:05:50 -0800
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> If I understand what you're saying, that means
>     autoload this/here/file
> creates a function named "this/here/file" by loading "file" from
> $^fpath/this/here  ... yes?
> And then (before this patch)
>     autoload /this/here/file
> creates a function named "/this/here/file" from the same location?
> So after this patch there is no way to autoload a function whose name
> begins with a slash.  Not that it was especially useful to be able to
> do so, just confirming.

Yes, that all looks like it's correct.

> If I may make a suggestion -- an equally useful variation would be for
> autoload to search the $fpath at the time of the autoload command and
> store the path where the file is found *iff* it is found.  This would
> be sort of like doing
>     autoload -Uz $^fpath/myfunc(N)
> except that it handles the situation where $fpath does not yet contain
> the "myfunc" file.
> Another useful variation might be to fall back to the current fpath if
> the function isn't found at the specified location.

These need some form of new syntax, but it looks like options are
probably good enough.  -r for remember the path where found (or -s for
save/store?) and -c for use current fpath as default (or -d for default?
anything with -f or -p being a bit vague in this context).

-R for remember and also ensure it's there with a hard error if it isn't
there would be possible if it seems useful --- it gives you a way you
don't currently have of expressing the fact the function is required and
you might as well bomb out immediately rather than once you're committed
to doing whatever.

Presumably -c should remember the path, even if it found it on $fpath
rather than the specified location, to avoid surprises.

We're at the point where autoload isn't really a synonym of functions -u
any more.  I'd be tempted to document "functions -u" as "implements a
limited subset of..." rather than "equivalent to...".  (Does anyone use
that interface except for compatibility?)


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