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

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.  Using strcmp() is
> not ideal, since one actully is permitted to create a function named
> '(anon)' [though it would be ugly/confusing to call it].

It might be better to use a named constant for the string "(anon)" so
that a pointer comparison can be used instead of strcmp(). Either that
or add space for flags in the shfunc structure.

> IIRC the extra pass of alias expansion was discounted because by the
> time you invoke "autoload -X" you presumably have alreay reached the
> function via a name that isn't an alias.

It is a bit of a hack, though. I couldn't see an alternative without
making functions in exec.c non-static.

> } 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
implemented. 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
functions). 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.

Oliver




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