Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: autoloading questions
- X-seq: zsh-users 2686
- From: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh users mailing list <zsh-users@xxxxxxxxxxxxxx>
- Subject: Re: autoloading questions
- Date: Fri, 15 Oct 1999 09:18:01 +0000
- In-reply-to: <19991014165452.A31729@xxxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxxxxxx; run by ezmlm
- References: <19991014165452.A31729@xxxxxxxxxxxxxxxxxxxxxxx>
On Oct 14, 4:54pm, Adam Spiers wrote:
} Subject: autoloading questions
}
} 1. What's the best way of checking whether an autoload of a function
} will succeed? (I mean the actual loading, rather than the
} invocation of the `autoload' built-in.)
I can't think of anything except
function testauto {
emulate -L zsh
local f
f=( $^fpath/$1(N) )
[[ -n $f[1] ]] && $ZSH_NAME -ns < $f[1]
}
That requires forking an extra shell, though, and it's still nothing
more than a syntax check.
} 2. How can I manually cause an autoloaded function to be loaded
} without actually running it
Try this:
function loadauto {
emulate -L zsh
local f
f=( $^fpath/$1(N) )
eval "function $1 {
$(< $f[1])
}"
}
(You can replace $(< $f[1]) with $mapfile[$f[1]] if you use that module,
but $(<...) is already a non-forking special-case.)
Actually, I guess calling loadauto would tell you whether the autoload
succeeds, so it sort of answers both questions ....
BTW, this question made me notice that it's not a good idea to do
autoload fun
zmodload parameter
noglob vared functions[fun]
unless you're very careful about whether you press enter.
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Messages sorted by:
Reverse Date,
Date,
Thread,
Author