From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18115 invoked by alias); 19 Sep 2016 07:01:31 -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: 39383 Received: (qmail 19357 invoked from network); 19 Sep 2016 07:01:31 -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.566454 secs); 19 Sep 2016 07:01:31 -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:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=ycPzN4eSbV+IY5L/ ciJ7LiAkxAw=; b=hoLw9Y11fWOjL1hHKeomW8fyPhH3KR7rUP5bFljP+9Mj5sM4 4BPOUmHmHwscO/irQcQxjuH6oQR7eFgQnPR5D767VQKQYIQJVert53ZEMdJnDL+y U3AUS9g05S0Yw+M3bisHb58eDTFgBXLdlfo+MYUrpDfFhDGAVomNz8af8/8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=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=ycPzN4eSbV+IY5L /ciJ7LiAkxAw=; b=TnhGvryV5xlipAgpF7lsLPlBraPMUPFsEXAbDKsimrUkG3g q2/yJrO5C+d/AMXm+ss/tceE8Tmk1hRQuhkswVJLyzSDwDMapLG71MeyumOScjZf xCjo22AwP5PMZ1s6rTRuF4h89Rv+3IlND/Xaps06ZfOlmSqQ/c6SNmzUvbvQ= X-Sasl-enc: +p967lPHvF5CmbbqnMXNN3NAc6WbYRR7p5VEBOJkUExX 1474268481 Date: Mon, 19 Sep 2016 07:00:22 +0000 From: Daniel Shahaf To: zsh-workers@zsh.org Subject: Re: 'compadd -P' matches $PREFIX greedily Message-ID: <20160919070022.GA3868@fujitsu.shahaf.local2> References: <20160917063258.GA26826@fujitsu.shahaf.local2> <69990.1474162087@hydra.kiddle.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <69990.1474162087@hydra.kiddle.eu> User-Agent: Mutt/1.5.23 (2014-03-12) Oliver Kiddle wrote on Sun, Sep 18, 2016 at 03:28:07 +0200: > Daniel Shahaf wrote: > > The following completion function: > > > > % compdef 'compadd -P p_____ papa mama nana aaaa' f > > % f pa → p_____aaaa > > Out of interest, was there a real prefix where you came across this. Yes, I ran into it in _bts. I'll send that patch separately for X-Seq purposes, but the tl;dr is: _f() { _email_addresses -c -P "from:" } _email-foo() { compadd eee fee } f fe → from:eee where «from:fee» was the expected result. > I was trying to think of more realistic prefixes to see how this > might affect them: > > % compdef 'compadd -P file:// /papa //mama /nana aaaa filter' f > > before: f fil → file:// > after : f fil → file://filter > > That now seems a bit too aggressive. > Agreed. The ability to complete the prefix "file://" shouldn't depend on what hostnames (matches) are available. Especially as hostnames (and email addresses) are added and removed over time. > How about allowing the longest common prefix to be equal to either > the -P prefix or equal to $PREFIX. In both of our examples, the last character of $compadd_args[-P] is a delimiter. For fil I'm not sure what's right. Perhaps we should offer both «file://» (offering all five matches) and «file://filter». I'm not certain how the UI for this would look. Conceptually, it would involve trying two different values for the common prefix: both 0 (the empty string) and min(${#PREFIX}, ${#compadd_args[-P]}) if one of those two is a prefix of the other. I'm not sure how easy or hard trying two values would be to implement. In the meantime, an interdiff implementing your suggestion is attached. I'm inclined to commit it, and we can tweak it further later if need be. Cheers, Daniel Interdiff: diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c index 05d2706..5443018 100644 --- a/Src/Zle/compcore.c +++ b/Src/Zle/compcore.c @@ -2194,8 +2194,10 @@ addmatches(Cadata dat, char **argv) /* Test if there is an existing -P prefix. */ if (dat->pre && *dat->pre) { int prefix_length = pfxlen(dat->pre, lpre); - if (dat->pre[prefix_length] == '\0') { - /* $compadd_args[-P] is a prefix of ${PREFIX}. */ + if (dat->pre[prefix_length] == '\0' || + lpre[prefix_length] == '\0') { + /* $compadd_args[-P] is a prefix of ${PREFIX}, or + * vice-versa. */ llpl -= prefix_length; lpre += prefix_length; }