Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: perl -d: completion bug
- X-seq: zsh-workers 25854
- From: Phil Pennock <zsh-workers+phil.pennock@xxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: PATCH: perl -d: completion bug
- Date: Sun, 12 Oct 2008 01:58:45 -0700
- 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=;
- In-reply-to: <081011110236.ZM18486@xxxxxxxxxxxxxxxxxxxxxx>
- Mail-followup-to: zsh-workers@xxxxxxxxxx
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <20081011053503.GA93211@xxxxxxxxxxxxxxxxxxxx> <081011110236.ZM18486@xxxxxxxxxxxxxxxxxxxxxx>
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
}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author