From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26600 invoked by alias); 19 Sep 2012 14:58:43 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 30682 Received: (qmail 950 invoked from network); 19 Sep 2012 14:58:32 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <120919075811.ZM24917@torch.brasslantern.com> Date: Wed, 19 Sep 2012 07:58:11 -0700 In-reply-to: <1348021726.8764.YahooMailNeo@web29706.mail.ird.yahoo.com> Comments: In reply to Oliver Kiddle "Re: autoload -X inside an anonymous function" (Sep 19, 3:28am) References: <13194.1347934322@thecus.kiddle.eu> <120918095827.ZM23535@torch.brasslantern.com> <1348021726.8764.YahooMailNeo@web29706.mail.ird.yahoo.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: Zsh workers Subject: Re: autoload -X inside an anonymous function MIME-version: 1.0 Content-type: text/plain; charset=us-ascii 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 } implemented. 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 } functions). 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.