From: Phil Pennock <zsh-workers+phil.pennock@spodhuis.org>
To: zsh-workers@sunsite.dk
Subject: PATCH: perl -d: completion bug
Date: Sun, 12 Oct 2008 01:58:45 -0700 [thread overview]
Message-ID: <20081012085845.GA8246@redoubt.spodhuis.org> (raw)
In-Reply-To: <081011110236.ZM18486@torch.brasslantern.com>
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
}
prev parent reply other threads:[~2008-10-12 8:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-11 5:35 Phil Pennock
2008-10-11 18:02 ` Bart Schaefer
2008-10-12 8:58 ` Phil Pennock [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20081012085845.GA8246@redoubt.spodhuis.org \
--to=zsh-workers+phil.pennock@spodhuis.org \
--cc=zsh-workers@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).