* perl -d: completion bug
@ 2008-10-11 5:35 Phil Pennock
2008-10-11 18:02 ` Bart Schaefer
0 siblings, 1 reply; 3+ messages in thread
From: Phil Pennock @ 2008-10-11 5:35 UTC (permalink / raw)
To: zsh-workers
My zsh completion-fu is weak, still. Is there a way in which a function
calling another function to do the work can interrupt a _wanted() to
filter the results, or do I need to re-factor the function currently
calling _wanted() into a helper function which does the work and a
wrapper with the current name which calls _wanted(), then use that new
function?
There's a bug in the Perl completion. perl -d:<tab> completes all Perl
modules. What it needs to complete is the sub-string of module names in
the Devel:: namespace, after the Devel::.
The current _perl_modules() uses the caching system to good effect and I
want to keep that, cache all the modules in the same way (might as well,
even for a -d:<tab> completion) and then just filter to a sub-set.
Eg, given the module Devel::Trace installed, you'd invoke Perl thusly:
zsh% perl -d:Trace -e $'print "foo\\n";\nprint "bar\\n";'
>> -e:1: print "foo\n";
foo
>> -e:2: print "bar\n";
bar
zsh%
(And if the answer is trivial, please don't wait on a patch from me!)
Thanks,
-Phil
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: perl -d: completion bug
2008-10-11 5:35 perl -d: completion bug Phil Pennock
@ 2008-10-11 18:02 ` Bart Schaefer
2008-10-12 8:58 ` PATCH: " Phil Pennock
0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2008-10-11 18:02 UTC (permalink / raw)
To: zsh-workers
On Oct 10, 10:35pm, Phil Pennock wrote:
}
} There's a bug in the Perl completion. perl -d:<tab> completes all Perl
} modules. What it needs to complete is the sub-string of module names in
} the Devel:: namespace, after the Devel::.
If it were just a matter of restricting to the "Devel::" namespace,
you could change _perl to replace
'-d\:-[run under control of a debugging/tracing module]:debugging/tracing module:_perl_modules' \
with
'-d\:-[run under control of a debugging/tracing module]:debugging/tracing module:_perl_modules -F "( *~Devel\:\: )"' \
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* PATCH: perl -d: completion bug
2008-10-11 18:02 ` Bart Schaefer
@ 2008-10-12 8:58 ` Phil Pennock
0 siblings, 0 replies; 3+ messages in thread
From: Phil Pennock @ 2008-10-12 8:58 UTC (permalink / raw)
To: zsh-workers
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
}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-10-12 8:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-11 5:35 perl -d: completion bug Phil Pennock
2008-10-11 18:02 ` Bart Schaefer
2008-10-12 8:58 ` PATCH: " Phil Pennock
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).