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

Re: Load autoloadable function, but only in enclosing function scope



On Thu, Mar 24, 2022 at 10:51 AM Bart Schaefer
<schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> On Thu, Mar 24, 2022 at 10:06 AM Peter Stephenson
> >
> > 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.
>
> It actually can be even shorter than that, depending on how carefully
> the context needs to be preserved.

Copy-paste error, I missed the closing paren on this assignment:

  local funcs=(${(kv)functions})

One more note after re-reading the original request more closely:

On Thu, Mar 24, 2022 at 9:13 AM Zach Riggle <zachriggle@xxxxxxxxx> wrote:
>
> myfunc() {
>     autoload foo && foo
> }
>
> Such that foo and any other functions it declares are local-scope only?

If "foo" is already defined, it has to be removed with "unfunction
foo" before "autoload foo" will have any effect.  The "&&" there
doesn't help, because autoload is a silent but status-zero no-op for
functions that are already defined.  "autoload -R foo && foo" would
solve that.




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