From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7968 invoked by alias); 5 Oct 2015 22:03:02 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 36789 Received: (qmail 28730 invoked from network); 5 Oct 2015 22:02:58 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) 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.0 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=MSAIhhUp7al0f/cY qjtwG+GXq5M=; b=27QBpCgPFJUD6nEBmccy9TGWO/bRPK+6/GL6M4bVM8N7Y9H7 Zfz0mtMVLTQsYpwgzFJFHUjRTu4QqOmUOn/tE8nc32CS/IXqMPG9+v6rcTLt+i9E vvt3zOipaUfRzdVt7RWkQumn061CbCAaSGE2qJMMTnRpjNtTAXnuijdhm8Q= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=MSAIhhUp7al0f/c YqjtwG+GXq5M=; b=GjITJv/1JUwAaN14reM5G8PUSJOoMDBGxpD394F/SsX9W9O 4DZhEonZhlsudyZdqsTxHTWc1hwiKXwedUsVfpujA1Po3+J0qGiL1FkfpxxvEGXg WYQfbOCImTRw3biSe1nebfS5rrgUomuWtj1f8cPzfL/e0z03XUMgE6d7YFRQ= X-Sasl-enc: 6uqZU6bfkpjIga8uxMOFzayZkDpMGaRsE4sluLPfQt6q 1444081911 Date: Mon, 5 Oct 2015 21:51:34 +0000 From: Daniel Shahaf To: Bart Schaefer Cc: zsh-workers@zsh.org Subject: Re: [PATCH] Add API wrapper to ${+_comps[...]} Message-ID: <20151005215134.GA1959@tarsus.local2> References: <20150930182948.GD2003@tarsus.local2> <151003174919.ZM31542@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <151003174919.ZM31542@torch.brasslantern.com> User-Agent: Mutt/1.5.21 (2010-09-15) Bart Schaefer wrote on Sat, Oct 03, 2015 at 17:49:19 -0700: > On Sep 30, 6:29pm, Daniel Shahaf wrote: > } > } I wonder if this is useful enough to be added? > > (Why two separate patches both to compsys.yo?) > One logical change per commit. I might have erred on the side of splitting too much, but it's easier to unsplit than to split.) > I don't see any particular reason not to add it, but I also find > no existence tests of $_comps[...] anywhere in the contributed > functions or my own local startup files or functions, so it may > indeed be only minimally useful. > I use them like this in my .zshrc: # TODO neither of this actually works, since _gnu_generic wants # --foo=[VALUE] and these have a space instead, but they get 90% # right and are better than nothing... _has_completion() { (( $# == 1 )) || return 2; (( $+_comps[$1] )) } _has_completion howdoi || compdef _gnu_generic howdoi _has_completion ag || compdef _gnu_generic ag The idea is to be forward compatible — to only install the _gnu_generic definition if there isn't an _ag already defined. > On the other hand there are tests for whether a particular function > is defined. If that function is destined to be assigned to _comps[x] > perhaps it would be better to check for _comps[x] already defined > instead. _comps[x] being already defined in what sense? I can think of three meanings: (a) hash key exists; (b) hash key exists and the value has exists as a key in $functions; (c) same, plus the function is not a "marked-for-autoload" stub. The patch implements (a). I think we could leave the patch doing (a) — that's meaningful, it checks whether 'x ' has been hooked — and let callers that care about (b) or (c) implement the extra check (b) or (c) do it themselves?