zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Re: Load autoloadable function, but only in enclosing function scope
Date: Thu, 24 Mar 2022 11:34:26 -0700	[thread overview]
Message-ID: <CAH+w=7bKw2AtVrN3A0rrwp9UarNYu4wVHPNc3oxhdY1j3oaoWA@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7Yxm-s7jFFW4MLZ5NzRUeJ1tF5R=YSUjQs1M8FX-J-6Ow@mail.gmail.com>

On Thu, Mar 24, 2022 at 10:51 AM Bart Schaefer
<schaefer@brasslantern.com> 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@gmail.com> 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.


  reply	other threads:[~2022-03-24 18:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-24 16:12 Zach Riggle
2022-03-24 16:29 ` Mikael Magnusson
2022-03-24 17:05   ` Peter Stephenson
2022-03-24 17:51     ` Bart Schaefer
2022-03-24 18:34       ` Bart Schaefer [this message]
2022-03-24 19:52       ` Peter Stephenson
2022-03-25  0:27         ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7bKw2AtVrN3A0rrwp9UarNYu4wVHPNc3oxhdY1j3oaoWA@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    --subject='Re: Load autoloadable function, but only in enclosing function scope' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this inbox:

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).