Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: completion for perl
- X-seq: zsh-workers 10087
- From: Adam Spiers <adam@xxxxxxxxxx>
- To: zsh workers mailing list <zsh-workers@xxxxxxxxxxxxxx>
- Subject: PATCH: completion for perl
- Date: Sun, 12 Mar 2000 13:28:00 +0000
- Mail-followup-to: zsh workers mailing list <zsh-workers@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
- Reply-to: Adam Spiers <adam@xxxxxxxxxx>
Here's completion code for perl, and a few clean-ups to _perl_modules.
If anyone would be kind enough to tarball their latest working copy,
I'll be able to submit some more stuff (I guess I should also be
submitting a .yo patch for this new style, for example), but I'm
currently a bit helpless without CVS :-(
Whilst struggling with the mess which is _perl_config_vars below, it
struck me how an equivalent of compset -P which matched the /whole/ of
PREFIX rather than just the beginning would have come in handy. Is
this worthwhile, Sven, or is my whole approach coming from the wrong
angle? Also, as you can see from the compstate[quoting] line below, I
tried to get completion working for
$ perl -V:'<TAB>
and
$ perl -V:"<TAB>
so that it would insert a single space after each configuration
variable completed while within quotes, rather than a quoted single
space, but I didn't fully understand how compset -q works, and
couldn't stop it from eating up the opening quote. Help! :-)
Adam
Index: Completion/User/_perl_modules
===================================================================
--- Completion/User/_perl_modules Tue Nov 16 16:58:15 1999
+++ Completion/User/_perl_modules Sun Mar 12 11:59:32 2000
@@ -7,16 +7,22 @@
# Calculate all installed Perl modules. The result is cached
# for future use.
#
+# Available styles:
+#
+# * try-to-use-pminst
+#
+# Set this if you have pminst and want to use it. The zsh code
+# actually produces better results because pminst misses modules of
+# the form Foo/bar/Baz.pm through its clumsy -d && /^[A-Z]/ && prune
+# algorithm (the zsh code does almost the same, but only misses
+# modules which don't begin with an uppercase letter).
-# Change this if you have pminst and want to use it. The zsh code
-# actually produces better results because pminst misses modules of
-# the form Foo/bar/Baz.pm through its clumsy -d && /^[A-Z]/ && prune
-# algorithm (the zsh code does almost the same, but only misses modules
-# which don't begin with an uppercase letter).
-local try_to_use_pminst=0
+local opts
+zparseopts -D -a opts S: q
if [[ ${+_perl_modules} -eq 0 ]]; then
- if [[ $try_to_use_pminst -ne 0 ]] && which pminst >/dev/null; then
+ if zstyle -t ":completion:${curcontext}:modules" try-to-use-pminst \
+ && which pminst >/dev/null; then
_perl_modules=( $(pminst) )
else
local inc libdir new_pms
@@ -43,4 +49,4 @@
local expl
-_wanted modules expl 'Perl modules' && compadd "$expl[@]" - $_perl_modules
+_wanted modules expl 'Perl modules' && compadd "$expl[@]" "$opts[@]" - $_perl_modules
Index: Completion/User/_perl
===================================================================
--- /dev/null Tue May 5 21:32:27 1998
+++ Completion/User/_perl Sun Mar 12 13:13:49 2000
@@ -0,0 +1,65 @@
+#compdef perl
+#
+# zsh completion code for the Perl interpreter
+# Adam Spiers <adam@xxxxxxxxxx>
+#
+
+_perl () {
+ _arguments -s \
+ '-0-:input record separator in octal (\0, if no argument): ' \
+ '-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-: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.: " \
+ '-h[list help summary]' \
+ '-i-[edit <> files in place (make backup if extension supplied)]:backup file extension: ' \
+ '-I-[specify @INC/#include directory (may be used more than once)]:include path:_files -/' \
+ '-l-[enable line ending processing, specifies line terminator]:output record separator in octal: ' \
+ {-m,-M}"-[module.. executes \`use/no module...' before executing your script.]:module:_perl_m_opt" \
+ "-n[assume 'while (<>) { ... }' loop around your script]" \
+ "-p[assume loop like -n but print line also like sed]" \
+ "-P[run script through C preprocessor before compilation]" \
+ "-s[enable some switch parsing for switches after script name]" \
+ "-S[look for the script using PATH environment variable]" \
+ "-T[turn on tainting checks]" \
+ "-u[dump core after parsing script]" \
+ "-U[allow unsafe operations]" \
+ "-v[print version number, patchlevel plus VERY IMPORTANT perl info]" \
+ "-V-[print perl configuration information]:configuration keys:_perl_config_vars" \
+ '-w[TURN WARNINGS ON FOR COMPILATION OF YOUR SCRIPT. Recommended.]' \
+ '-x-[strip off text before #!perl line and perhaps cd to directory]:directory to cd to:_files -/' \
+ ':Perl script:_files -g \*.pl'
+}
+
+_perl_m_opt () {
+ compset -P '-'
+
+ if compset -P '*='; then
+ _message 'module arguments, comma separated'
+ else
+ _perl_modules -S= -q
+ fi
+}
+
+_perl_config_vars () {
+ if (( ! $+_perl_config_vars )); then
+ # perl | perl ... nasty, but is there another way?
+ _perl_config_vars=( $(perl -V |
+ perl -ne 'push @m, (/(\w+)(?==)/g);' \
+ -e 'END {print join "\n", @m}' ) )
+ fi
+
+ local add_colon='-P:'
+ compset -P '*:' && add_colon=''
+
+ local delimiter='\ '
+ (( compstate[quoting] )) && delimiter=' '
+
+ compset -P '* ' && compset -q
+ compadd "$expl[@]" $add_colon -S$delimiter -q - $_perl_config_vars
+}
+
+_perl "$@"
Messages sorted by:
Reverse Date,
Date,
Thread,
Author