From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4836 invoked by alias); 22 Jun 2016 18:42:54 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 21696 Received: (qmail 10965 invoked from network); 22 Jun 2016 18:42:52 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 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== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version; bh=XVbKaGlCMiithb1n72dJYbAn6hjbUaEZCrdmuDFQ1rE=; b=XOFkTjkpGn0vRJsgd36WbH9+op1vpaKgb8s2BjMG2AiHxNIZnV8LDs54RxAOyN9irB +DRfJ+jVUaHBXt3oYW8euT3PTLLechYByuWBh+K7n2lXNrX233+LkBz8M602dL50URDK wgUBg5EztdwVPzvdeuO0kRzrfAFUZkOmnMP7QzUIANrwNw17FdLOrOgBumF+NqqjMgwM XfgvuCE+ZHM9R1tzZOXWOx8digK285CxM7B8xRdQXir6yJ7qrTo6RIKnrGyHi/PBAvyS BgCBBVgn1OlmE6/ZU/qpkB+x1ekMEdE424i7HMsV6tRJ/1KLVRWRmCWBpURCflxEVGDD pnPQ== X-Gm-Message-State: ALyK8tKs0VyS7tR73uxDVq2UvLOgmt0NNDUJpch8OKUZ1pkf1s6h0d7CpxUTeoAc5EwLHw== X-Received: by 10.98.89.85 with SMTP id n82mr35529625pfb.23.1466620970783; Wed, 22 Jun 2016 11:42:50 -0700 (PDT) From: Bart Schaefer Message-Id: <160622114326.ZM12463@torch.brasslantern.com> Date: Wed, 22 Jun 2016 11:43:26 -0700 In-Reply-To: <20160621014130.GA9067@tarsus.local2> Comments: In reply to Daniel Shahaf "Re: Is the function $f defined and is not an autoload stub?" (Jun 21, 1:41am) References: <20160615232447.GA27645@tarsus.local2> <160616091615.ZM24804__45250.1349304386$1466093823$gmane$org@torch.brasslantern.com> <20160621014130.GA9067@tarsus.local2> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: Is the function $f defined and is not an autoload stub? MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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.