Zsh Mailing List Archive
Messages sorted by:
Re: autoload -X inside an anonymous function
On Sep 19, 3:28am, Oliver Kiddle wrote:
} Subject: Re: autoload -X inside an anonymous function
} Bart wrote:
} > Aside mostly to PWS: Is there any way to detect that you are in the
} > anonymous function? (!scriptname) means you aren't in any function at
} > all, which is what bin_functions() is testing for.
} It might be better to use a named constant for the string "(anon)" so
} that a pointer comparison can be used instead of strcmp().
That would work. I was hoping there was already something else in the
global state, but it appears that only execfuncdef() knows for sure.
} > } While looking at that relevant bits of code, I also wonder whether
} > } the second call to eval_autoload is reachable code: no builtin using
} > } bin_functions allows both the -m and -X options.
} > It definitely is not reachable because of the test at about line 2686 in
} > builtin.c -- the second eval_autoload likely is there for completeness
} > (in case somebody later adds a builtin that allows a mass autoload).
} I would have assumed it was a cut and paste remnant from when -m was
Can't be, -m was implemented years before -X was.
} I can't see any reason why it wouldn't work if you simply
} added -m to the list of options accepted by autoload (or -X to
I misread the test at 2686 -- that one is using OPT_MINUS(), whereas
the one at 2876 is OPT_ISSET(). So this is there specifically *to*
implement "autoload -m +X", even though autoload doesn't currently
allow -m in its args list.
} Not that it'd be especially useful; even your "autoload -m +X \*"
} example is perhaps only useful for checking there's no parse
} errors in any functions.
The real usage would be to temporarily change FPATH, load all the
functions defined in that alternate path, and then restore the old
FPATH. This might be to resolve search order dependency issues.
Messages sorted by: