From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25112 invoked from network); 8 Nov 2008 23:29:21 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 8 Nov 2008 23:29:21 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 2556 invoked from network); 8 Nov 2008 23:29:12 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 8 Nov 2008 23:29:12 -0000 Received: (qmail 23113 invoked by alias); 8 Nov 2008 23:29:03 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 26021 Received: (qmail 23095 invoked from network); 8 Nov 2008 23:29:02 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 8 Nov 2008 23:29:02 -0000 Received: from mtaout01-winn.ispmail.ntl.com (mtaout01-winn.ispmail.ntl.com [81.103.221.47]) by bifrost.dotsrc.org (Postfix) with ESMTP id 3A0F480308BE for ; Sun, 9 Nov 2008 00:28:58 +0100 (CET) Received: from aamtaout02-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout01-winn.ispmail.ntl.com (InterMail vM.7.08.04.00 201-2186-134-20080326) with ESMTP id <20081108232858.SZBP1869.mtaout01-winn.ispmail.ntl.com@aamtaout02-winn.ispmail.ntl.com> for ; Sat, 8 Nov 2008 23:28:58 +0000 Received: from pws-pc ([81.107.43.40]) by aamtaout02-winn.ispmail.ntl.com (InterMail vG.2.02.00.01 201-2161-120-102-20060912) with ESMTP id <20081108232858.OEQU21638.aamtaout02-winn.ispmail.ntl.com@pws-pc> for ; Sat, 8 Nov 2008 23:28:58 +0000 Date: Sat, 8 Nov 2008 23:28:54 +0000 From: Peter Stephenson To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: Re: PATCH: completion of glob qualifiers Message-ID: <20081108232854.07b2c8a2@pws-pc> In-Reply-To: <12404.1226061536@thecus> References: <11164.1203725067@pws-pc> <12404.1226061536@thecus> X-Mailer: Claws Mail 3.5.0 (GTK+ 2.12.12; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Cloudmark-Analysis: v=1.0 c=1 a=NLZqzBF-AAAA:8 a=CfP_lW2gSqs9jFEUqugA:9 a=Al3d-iUb--ctS4c5scUA:7 a=Lpah9i0JGXqXYMY-_k5lLU0rJIAA:4 a=VkNj9pNNdSIA:10 a=-hJg1tCh9CgA:10 a=_dQi-Dcv4p4A:10 a=LY0hPdMaydYA:10 X-Virus-Scanned: ClamAV 0.92.1/8593/Sat Nov 8 19:05:01 2008 on bifrost X-Virus-Status: Clean On Fri, 07 Nov 2008 13:38:56 +0100 Oliver Kiddle wrote: > I've only just noticed this change back in message 24585. Is there any > reason why globbing flags were not completed. This patch adds them. Fine, the patch was simply incomplete. The patch below will mess yours up, however. > Note that inside [[ ... ]] conditions, a bracket that is not preceded by > some other character is assumed to be used for grouping of conditions so > this won't work with glob flags at the beginning of a pattern. We shouldn't complete glob flags right at the start of a word, presumably---I don't think that's ever going to be useful. I've added a test that we're skipping over at least one character before the parenthesis for a bare glob. It seems the completion options always add BARE_GLOB_QUAL, in fact; it would probably make more sense to rely on the use of (#q...) inside the completion system, but I'm too lazy to fix this. > One problem possibly due to your original patch is the following; > : */( > results in the /( being removed. I haven't worked out why but this > doesn't occur with the old zsh that comes with Debian stable. I'm not sure why I thought it was a good idea to match glob qualifiers at a complicated point in the middle of path matching. Even if the qualifiers aren't after a glob expression, which they typically are, you don't want to do completion on the earlier path if you're already completing a qualifier. I've therefore simply moved the chunk to the start of _path_files. Index: Completion/Unix/Type/_path_files =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_path_files,v retrieving revision 1.39 diff -u -r1.39 _path_files --- Completion/Unix/Type/_path_files 29 Oct 2008 21:59:32 -0000 1.39 +++ Completion/Unix/Type/_path_files 8 Nov 2008 23:13:30 -0000 @@ -1,5 +1,30 @@ #autoload +local -a match mbegin mend + +# Look for glob qualifiers. Do this first: if we're really +# in a glob qualifier, we don't actually want to expand +# the earlier part of the path. We can't expand inside +# parentheses otherwise, so as we test that successfully +# we should be able to commit to glob qualifiers here. +# +# Extra nastiness to be careful about a quoted parenthesis. +# The initial tests look for parentheses with zero or an +# even number of backslashes in front. We also require that +# there was at least one character before the parenthesis for +# a bare glob qualifier. +# The later test looks for an outstanding quote. +if [[ ( -o bareglobqual && \ + $PREFIX = (#b)((*[^\\]|)(\\\\)#\()([^\)]#) && \ + ${#match[1]} -gt 1 || \ + -o extendedglob && \ + $PREFIX = (#b)((*[^\\]|)(\\\\)#"(#q")([^\)]#) \ + ) && -z $compstate[quote] ]]; then + compset -p ${#match[1]} + _globquals + return +fi + # Utility function for in-path completion. This allows `/u/l/b' # to complete to `/usr/local/bin'. @@ -9,7 +34,7 @@ local nm=$compstate[nmatches] menu matcher mopts sort mid accex fake local listfiles listopts tmpdisp origtmp1 Uopt integer npathcheck -local -a match mbegin mend Mopts +local -a Mopts typeset -U prepaths exppaths @@ -383,19 +408,7 @@ tmp2=( "$tmp1[@]" ) - # Look for glob qualifiers. - # Extra nastiness to be careful about a quoted parenthesis. - # The initial tests look for parentheses with zero or an - # even number of backslashes in front. - # The later test looks for an outstanding quote. - if [[ ( -o bareglobqual && \ - "$tpre/$tsuf" = (#b)((*[^\\]|)(\\\\)#\()([^\)]#) || \ - -o extendedglob && \ - "$tpre/$tsuf" = (#b)((*[^\\]|)(\\\\)#"(#q")([^\)]#) \ - ) && -z $compstate[quote] ]]; then - compset -p ${#match[1]} - _globquals - elif [[ "$tpre$tsuf" = */* ]]; then + if [[ "$tpre$tsuf" = */* ]]; then compfiles -P$cfopt tmp1 accex "$skipped" "$_matcher $matcher[2]" "$sdirs" fake elif [[ "$sopt" = *[/f]* ]]; then compfiles -p$cfopt tmp1 accex "$skipped" "$_matcher $matcher[2]" "$sdirs" fake "$pats[@]" -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/