From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20163 invoked by alias); 17 Sep 2016 06:33:58 -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: 39372 Received: (qmail 6568 invoked from network); 17 Sep 2016 06:33:58 -0000 X-Qmail-Scanner-Diagnostics: from out2-smtp.messagingengine.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(66.111.4.26):SA:0(0.0/5.0):. Processed in 0.163593 secs); 17 Sep 2016 06:33:58 -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=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at daniel.shahaf.name does not designate permitted sender hosts) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=content-transfer-encoding:content-type :date:from:message-id:mime-version:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=5ielzk1WiCzImvFXEybNFIRHf3c=; b=OXRu9z 435BQs9MLG9uhCwV27v7950+XsabOmnHf7LHOaXnbwiZFdpAAJcB1UwftBIDkmx7 gxTb55+5Q1SJhYnE8nBGjhW8pOdQX9PFfJycgrH6jmRMKgNgncS5LzM0oFdGG1LW THQnGni3/Dv6HrzvKLB2gQPdq+pZafVCTmbSY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:message-id:mime-version:subject:to:x-sasl-enc :x-sasl-enc; s=smtpout; bh=5ielzk1WiCzImvFXEybNFIRHf3c=; b=ef324 ip2yK8IK5J3zwmfMZVg7gDjeYCJ0tm/oK4GHHtx+u+SzHznhb5rll8rpo9y4u9n1 6zFkkFhFDDGQ4rf6mq8my283setpDRJa80b1nIWi9bti8cWVJZ+OgBFg7iVQS2Qq LRK3X/8xBHi4N/ZM6SCaT69KUrIMoNlmjp4+UA= X-Sasl-enc: fvYq0mKUcBVXm1UIPlKsROIfhfnjPx2THdX/nsAS4Wpc 1474094035 Date: Sat, 17 Sep 2016 06:32:58 +0000 From: Daniel Shahaf To: zsh-workers@zsh.org Subject: 'compadd -P' matches $PREFIX greedily Message-ID: <20160917063258.GA26826@fujitsu.shahaf.local2> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.5.23 (2014-03-12) The following completion function: % compdef 'compadd -P p_____ papa mama nana aaaa' f gives: % f ma → p_____mama % f na → p_____nana % f pa → p_____aaaa % % f pm → p_____mama % f pn → p_____nana % f pp → p_____papa % % f p_p → p_____papa I expected the third case to offer «p_____papa» as a completion, by analogy with the first two cases. The reason it doesn't is that the argument to the -P option («p_____») is matched with the command-line word («pa») and their common prefix is discarded from the command-line word before completion proceeds. For «pa» the common prefix is «p», leaving «a» as the command-line word, so completion looks for matches that start with «p_____a»; while for «ma» the common prefix is «» (empty string) so completion looks for matches that start with «p_____ma». This patch makes skipping the -P prefix an all-or-nothing affair: the -P prefix will only be skipped if it the longest common prefix it and ${PREFIX} have is equal to the -P prefix. diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c index 2f9fb33..05d2706 100644 --- a/Src/Zle/compcore.c +++ b/Src/Zle/compcore.c @@ -2029,7 +2029,7 @@ addmatches(Cadata dat, char **argv) char **aign = NULL, **dparr = NULL, *oaq = autoq, *oppre = dat->ppre; char *oqp = qipre, *oqs = qisuf, qc, **disp = NULL, *ibuf = NULL; char **arrays = NULL; - int lpl, lsl, pl, sl, bcp = 0, bcs = 0, bpadd = 0, bsadd = 0; + int lpl, lsl, sl, bcp = 0, bcs = 0, bpadd = 0, bsadd = 0; int ppl = 0, psl = 0, ilen = 0; int llpl = 0, llsl = 0, nm = mnum, gflags = 0, ohp = haspattern; int isexact, doadd, ois = instring, oib = inbackt; @@ -2193,9 +2193,12 @@ addmatches(Cadata dat, char **argv) /* Test if there is an existing -P prefix. */ if (dat->pre && *dat->pre) { - pl = pfxlen(dat->pre, lpre); - llpl -= pl; - lpre += pl; + int prefix_length = pfxlen(dat->pre, lpre); + if (dat->pre[prefix_length] == '\0') { + /* $compadd_args[-P] is a prefix of ${PREFIX}. */ + llpl -= prefix_length; + lpre += prefix_length; + } } } /* Now duplicate the strings we have from the command line. */ (Here lpre is ${PREFIX} and llpl is its strlen().) Thoughts? Cheers, Daniel