Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Is the function $f defined and is not an autoload stub?
- X-seq: zsh-users 21696
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Is the function $f defined and is not an autoload stub?
- Date: Wed, 22 Jun 2016 11:43:26 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=XVbKaGlCMiithb1n72dJYbAn6hjbUaEZCrdmuDFQ1rE=; b=LzRPxmfV7+A/4xp2NKi0JRpGbacpXsMmDbmp7sVjS6BPn+0HbgwW8fhNir/KDcBCfo j9vYh91YIdpyi8Amm68ZnAUCjGwKAqLDDBHZ6g1bsNia1m5tPbt299TANCfdYpB1zKvc mqWGk3cpAK1x8PxPtOkcJnFfbioiv6wshMAh5OUPLE4Zcpm9MKn2eoJP8wlh2iVBzcvc H/RSTEdjdXbykAx4D2Oc+5WWg0bDPiBIdpISjO8v/eu0B677yeqRldbQGAo3hMvuJjrg JGkGiNA1vOLbObLNUl3uo9+sQLtJ5q4cyBvlq+SM8o8JOMSqyaG+MH68JG91BiAsqp38 P0zg==
- In-reply-to: <20160621014130.GA9067@tarsus.local2>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <20160615232447.GA27645@tarsus.local2> <160616091615.ZM24804__45250.1349304386$1466093823$gmane$org@torch.brasslantern.com> <20160621014130.GA9067@tarsus.local2>
On Jun 21, 1:41am, Daniel Shahaf wrote:
}
} > I suppose for consistency "autoload xyz" should return false if the
} > function is already fully defined (though what to do in the case of
} > "autoload xyz pdq" where one is defined and the other is not is a
} > bit ambiguous even for the +X case). Right now "autoload xyz" never
} > returns nonzero that I can tell.
}
} So, if I read you correctly, this would enable the idiom 'if autoload +X
} $f; ! autoload $f; then' to test for fully-definedness?
I was thinking more of "if ! autoload $f || autoload +X $f; then" but I
guess your way also works. I might go so far as
if (( $+functions[$f] )) && { ! autoload $f || autoload +X $f }; then
to avoid autoloading something that was never intended to be so, but it
depends on whether you already know $f is in $fpath or whatever.
} The proposed would cause behaviour changes in certain cases: for
} example, in the case of a plugin that calls 'autoload add-zsh-hook &&
} add-zsh-hook foo bar' with errexit or printexitvalue in effect. (Yes,
} people do this: the idiom I learnt was "autoload foo && foo".)
Hmm. Yes, that would be a possible issue in the case where something
else had already both autoloaded and executed $foo.
I just realized there's another way to distinguish autoloads from full
functions in current versions:
if (( $+functions[$f] )); then
if [[ -z ${(M)$(typeset +f -u):#$f} ]]; then
print "$f is already fully defined"
elif ( autoload +X $f ); then
print "$f is callable"
fi
fi
Remove the subshell in the elif when you don't care whether you force
the function to load in the current shell.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author