From: Bart Schaefer <schaefer@brasslantern.com>
To: Peter Stephenson <p.w.stephenson@ntlworld.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: Load autoloadable function, but only in enclosing function scope
Date: Thu, 24 Mar 2022 17:27:14 -0700 [thread overview]
Message-ID: <CAH+w=7ZV1bMJHQwoc=VeCLeWVr-KwHMa3Do3YeqZt4KZ9iw9+g@mail.gmail.com> (raw)
In-Reply-To: <df3bf8b419fba5fd457ae8868581707b95bb5f44.camel@ntlworld.com>
On Thu, Mar 24, 2022 at 12:52 PM Peter Stephenson
<p.w.stephenson@ntlworld.com> wrote:
>
> You're also at the mercy of zsh's ability to convert internal structures
> into text and back, which is supposed to work, though not particularly
> efficiently.
Extending your previous suggestion, then:
local -a oldfuncs=(${(k)functions})
local autoloads=(${(k)functions[(R)builtin autoload -X*]})
local funcsrc=(${(kv)functions_source})
{
: ...
} always {
local funcs=(${(k)functions:|oldfuncs})
funcs=(${funcs:|autoloads})
(( $#autoloads )) && unfunction $autoloads
(( ${#funcs} )) && unfunction $funcs
local func src
for func src in $funcsrc; do
[[ $src = */$func && $functions[$func] == '' ]] &&
autoload -r $src
done
}
Handling .zwc files and unusual autoload flags left as an exercise.
Particularly difficult is autoloads from "sticky" option scopes.
prev parent reply other threads:[~2022-03-25 0:28 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
2022-03-24 19:52 ` Peter Stephenson
2022-03-25 0:27 ` Bart Schaefer [this message]
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=7ZV1bMJHQwoc=VeCLeWVr-KwHMa3Do3YeqZt4KZ9iw9+g@mail.gmail.com' \
--to=schaefer@brasslantern.com \
--cc=p.w.stephenson@ntlworld.com \
--cc=zsh-users@zsh.org \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public 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).