From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18497 invoked from network); 12 Oct 2008 08:59:16 -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=-1.3 required=5.0 tests=AWL autolearn=unavailable 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; 12 Oct 2008 08:59:16 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 66277 invoked from network); 12 Oct 2008 08:59:05 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 12 Oct 2008 08:59:05 -0000 Received: (qmail 8478 invoked by alias); 12 Oct 2008 08:58:54 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 25854 Received: (qmail 8453 invoked from network); 12 Oct 2008 08:58:52 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 12 Oct 2008 08:58:52 -0000 Received: from mx.spodhuis.org (redoubt.spodhuis.org [193.202.115.177]) by bifrost.dotsrc.org (Postfix) with ESMTPS id 4B83780524C0 for ; Sun, 12 Oct 2008 10:58:48 +0200 (CEST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=d200807; d=spodhuis.org; h=Received:Date:From:To:Subject:Message-ID:Mail-Followup-To:References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; b=kSc92mw+AQmaDZfkcBEq0wpudqEOwIeQCiuixx4AJVlAVqOnXBLtlVQ+TufC9eBusS8RBJSFv1/uEjek8nj5FAtruzNEURZENQnJhAJ5lE07Gsby9ntitsXNmyoZ+2dHlzYC0vTjavr3EaQbOGDxxUOE4yhB1JYPS3q9SXZY0EA=; Received: by smtp.spodhuis.org with local id 1Kowmj-0002GG-TS; Sun, 12 Oct 2008 08:58:45 +0000 Date: Sun, 12 Oct 2008 01:58:45 -0700 From: Phil Pennock To: zsh-workers@sunsite.dk Subject: PATCH: perl -d: completion bug Message-ID: <20081012085845.GA8246@redoubt.spodhuis.org> Mail-Followup-To: zsh-workers@sunsite.dk References: <20081011053503.GA93211@redoubt.spodhuis.org> <081011110236.ZM18486@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <081011110236.ZM18486@torch.brasslantern.com> X-Virus-Scanned: ClamAV 0.92.1/8414/Sun Oct 12 05:30:50 2008 on bifrost X-Virus-Status: Clean On 2008-10-11 at 11:02 -0700, Bart Schaefer wrote: > However, also stripping off the "Devel::" from the front of the matches > is a bit trickier. What you want is something like "compadd -W" except > that works for things other than filename prefixes. > > My best suggestion is to update _perl_modules to take an additional flag > that identifies the module namespace, and use that to change the name of > the caching policy, etc. Unfortunately I don't have free time right now > to attempt to code it up. Thanks for the pointers and confirming that there wasn't a short-cut I could use. I didn't change caching in any way because I think it's the wrong thing to do -- anyone using perl on the command-line and expecting tab-completion of "perl -d:" to work is also highly likely to also be tab-completing -M too. So the right thing to do is to let the cache contain all results, always, with the current logic and just filter the results for this particular call to _perl_modules(). Done. Thanks, -Phil Index: Completion/Unix/Command/_perl =================================================================== RCS file: /home/cvsroot/zsh/Completion/Unix/Command/_perl,v retrieving revision 1.8 diff -a -u -p -r1.8 _perl --- Completion/Unix/Command/_perl 1 Jun 2005 10:02:34 -0000 1.8 +++ Completion/Unix/Command/_perl 12 Oct 2008 08:38:46 -0000 @@ -10,7 +10,7 @@ _perl () { '-a[autosplit mode with -n or -p (splits $_ into @F)]' \ "-c[check syntax only (runs BEGIN and END blocks)]" \ '-d[run scripts under debugger]' \ - '-d\:-[run under control of a debugging/tracing module]:debugging/tracing module:_perl_modules' \ + '-d\:-[run under control of a debugging/tracing module]:debugging/tracing module:_perl_modules --strip-prefix --perl-hierarchy=Devel' \ '-D-:set debugging flags (argument is a bit mask or flags): ' \ "*-e+:one line of script. Several -e's allowed. Omit [programfile]." \ "-F-:split() pattern for autosplit (-a). The //'s are optional.: " \ Index: Completion/Unix/Type/_perl_modules =================================================================== RCS file: /home/cvsroot/zsh/Completion/Unix/Type/_perl_modules,v retrieving revision 1.5 diff -a -u -p -r1.5 _perl_modules --- Completion/Unix/Type/_perl_modules 2 Aug 2006 22:20:45 -0000 1.5 +++ Completion/Unix/Type/_perl_modules 12 Oct 2008 08:48:42 -0000 @@ -12,6 +12,17 @@ # -t[types]: indicate file types; currently the only one is -tP, # to include .pod files as well as modules. # +# --perl-hierarchy=...: restrict results to modules under this hierarchy. +# Note that this does not affect the filesystem searching or caching, +# which always collect all results on the premise that anyone using +# completion of Perl modules will use the results in various contexts, +# so this only affects the results compadd'd. +# +# --strip-prefix: when using --perl-hierarchy, strip off that prefix when +# passing to compadd. +# +# All other options passed onto compadd. +# # Available styles: # # * try-to-use-pminst @@ -26,14 +37,25 @@ _perl_modules () { # Set a sensible default caching policy. This has to be done inside # this function otherwise we wouldn't know the context for the style. local update_policy sufpat=".pm" with_pod + local restrict_hierarchy='' + local -i strip_perl_prefix zstyle -s ":completion:${curcontext}:" cache-policy update_policy if [[ -z "$update_policy" ]]; then zstyle ":completion:${curcontext}:" cache-policy \ _perl_modules_caching_policy fi - if [[ $argv[-1] = -tP ]]; then - argv=("${(@)argv[1,-2]}") + if [[ -n $argv[(r)--perl-hierarchy=*] ]]; then + restrict_hierarchy="${argv[(r)--perl-hierarchy=*]#--perl-hierarchy=}" + restrict_hierarchy="${restrict_hierarchy%::}::" + argv[(r)--perl-hierarchy=*]=() + fi + if [[ -n $argv[(r)--strip-prefix] ]]; then + strip_perl_prefix=1 + argv[(r)--strip-prefix]=() + fi + if [[ -n $argv[(r)-tP] ]]; then + argv[(r)-tP]=() sufpat="(.pm|.pod)" with_pod=_with_pod fi @@ -93,8 +115,18 @@ _perl_modules () { _store_cache ${perl_modules#_} $perl_modules fi - local expl + # Nothing above here should have filtered the results per-caller, so that + # the cache is always complete. From here on, it's safe to filter. + local -a perl_subset + if [[ -n $restrict_hierarchy ]]; then + perl_subset=( ${(PM)perl_modules:#${restrict_hierarchy}*} ) + if (( strip_perl_prefix )); then + perl_subset=( ${perl_subset#$restrict_hierarchy} ) + fi + perl_modules=perl_subset + fi + local expl _wanted modules expl 'Perl module' compadd "$@" -a - $perl_modules }