Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: completing perl record separators



The perl -0 and -l options allow for record separators to be specified
in octal which is perhaps useful on quick one-liners if you happen
to know the ASCII table in octal well. I'd guess that the sort of
characters most likely to used are neither octal digits nor other option
letters so this makes completion expand, e.g. -0: to -072

Aside from that, -00 and -0777 have special meanings which this makes
more explicit.

Furthermore, recent perl has a few new debug flags that were missing
from the completion and some exclusions are possible in the unicode
flags. I don't know if anyone objects to the removal of the comment at
the beginning but identifying original authors is what the git history
is for.

Perl is actually a rare case where we should be passing -W to _arguments
because option arguments can be mixed with other options but _arguments
doesn't really provide a good way to delimit the arguments.

Oliver

diff --git a/Completion/Unix/Command/_perl b/Completion/Unix/Command/_perl
index 0914264fe..4a917903c 100644
--- a/Completion/Unix/Command/_perl
+++ b/Completion/Unix/Command/_perl
@@ -1,14 +1,10 @@
 #compdef perl
-#
-# zsh completion code for the Perl interpreter
-# Adam Spiers <adam@xxxxxxxxxx>
-#
-# Completions currently based on Perl 5.14.1.
+
 typeset -A opt_args
 
 _perl () {
   _arguments -s \
-    '-0-[input record separator ($/)]:$/ in octal or hex (\0, if no argument)' \
+    '-0-[input record separator ($/)]:: :_perl_input_seps' \
     '-a[autosplit mode with -n or -p (splits $_ into @F)]' \
     '-C-[control some unicode features]: :_perl_unicode_flags' \
     "-c[check syntax only (runs BEGIN and END blocks)]" \
@@ -24,7 +20,7 @@ _perl () {
     '-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: ' \
+    '-l-[enable line ending processing, specifies line terminator]:: :_perl_output_seps' \
     \*{-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]" \
@@ -63,6 +59,27 @@ _perl_m_opt () {
   fi
 }
 
+_perl_input_seps() {
+  if [[ $#PREFIX -eq 1 && $PREFIX != [0-9a-zA-Z] ]]; then
+    # convert a non-octal or potential option character into octal representation
+    compadd -i "$IPREFIX" -U $(( [##8] ##$PREFIX ))
+  else
+    _describe -x -t separators "input record separator, $/ in octal or hex (\0, if no argument) [\n]" '(
+      0:paragraph\ mode
+      777:slurp\ whole\ input\ files
+    )' || _comp_mesg=yes
+  fi
+}
+
+_perl_output_seps() {
+  if [[ $#PREFIX -eq 1 && $PREFIX != [0-9a-zA-Z] ]]; then
+    # convert a non-octal or potential option character into octal representation
+    compadd -i "$IPREFIX" -U $(( [##8] ##$PREFIX ))
+  else
+    _message -e separators "output record separator, $\\ in octal or hex [$/]"
+  fi
+}
+
 _perl_config_vars () {
   if (( ! $+_perl_config_vars )); then
     _perl_config_vars=( $(perl -MConfig -e 'print join("\n", keys %Config);') )
@@ -80,44 +97,48 @@ _perl_config_vars () {
 
 _perl_unicode_flags () {
   _values -s '' 'unicode bitmask or flags' \
-    'I[  1 STDIN is assumed to be in UTF-8]' \
-    'O[  2 STDOUT will be in UTF-8]' \
-    'E[  4 STDERR will be in UTF-8]' \
-    'S[  7 I + O + E]' \
-    'i[  8 UTF-8 is the default PerlIO layer for input streams]' \
-    'o[ 16 UTF-8 is the default PerlIO layer for output streams]' \
-    'D[ 24 i + o]' \
+    '(S)I[  1 STDIN is assumed to be in UTF-8]' \
+    '(S)O[  2 STDOUT will be in UTF-8]' \
+    '(S)E[  4 STDERR will be in UTF-8]' \
+    '(I O E)S[  7 I + O + E]' \
+    '(D)i[  8 UTF-8 is the default PerlIO layer for input streams]' \
+    '(D)o[ 16 UTF-8 is the default PerlIO layer for output streams]' \
+    '(i o)D[ 24 i + o]' \
     'A[ 32 the @ARGV elements are expected to be strings encoded in UTF-8]' \
     'L[ 64 make "IOEioA" conditional on the locale environment variables]' \
     'a[256 set ${^UTF8CACHE} to -1, used for debugging]' \
 }
 
 _perl_debugging_flags () {
-  _values -s '' 'debugging bitmask or flags' \
-    'p[      1 Tokenizing and parsing (with v, displays parse stack)]' \
-    's[      2 Stack snapshots (with v, displays all stacks)]' \
-    'l[      4 Context (loop) stack processing]' \
-    't[      8 Trace execution]' \
-    'o[     16 Method and overloading resolution]' \
-    'c[     32 String/numeric conversions]' \
-    'P[     64 Print profiling info, preprocessor command for -P, source file input state]' \
-    'm[    128 Memory and SV allocation]' \
-    'f[    256 Format processing]' \
-    'r[    512 Regular expression parsing and execution]' \
-    'x[   1024 Syntax tree dump]' \
-    'u[   2048 Tainting checks]' \
-    'U[   4096 Unofficial, User hacking (reserved for private, unreleased use)]' \
-    'H[   8192 Hash dump -- usurps values()]' \
-    'X[  16384 Scratchpad allocation]' \
-    'D[  32768 Cleaning up]' \
-    'S[  66536 Thread synchronization]' \
-    'T[ 131072 Tokenising]' \
-    'R[ 262144 Include reference counts of dumped variables (eg when using -Ds)]' \
-    'J[ 524288 Do not s,t,P-debug (Jump over) opcodes within package DB]' \
-    'v[1048576 Verbose: use in conjunction with other flags]' \
-    'C[2097152 Copy On Write]' \
-    'A[4194304 Consistency checks on internal structures]' \
-    'q[8388608 quiet - currently only suppresses the "EXECUTING" message]' \
+  _values -s '' 'debug flag or bitmask' \
+    'p[        1 tokenizing and parsing (with v, display parse stack)]' \
+    's[        2 stack snapshots (with v, display all stacks)]' \
+    'l[        4 context (loop) stack processing]' \
+    't[        8 trace execution]' \
+    'o[       16 method and overload resolution]' \
+    'c[       32 string/numeric conversions]' \
+    'P[       64 print profiling info, source file input state]' \
+    'm[      128 memory and SV allocation]' \
+    'f[      256 format processing]' \
+    'r[      512 regular expression parsing and execution]' \
+    'x[     1024 syntax tree dump]' \
+    'u[     2048 tainting checks]' \
+    'U[     4096 unofficial, user hacking (reserved for private, unreleased use)]' \
+    'X[    16384 scratchpad allocation]' \
+    'D[    32768 cleaning up]' \
+    'S[    66536 Op slab allocation]' \
+    'T[   131072 tokenising]' \
+    'R[   262144 include reference counts of dumped variables (e.g. when using -Ds)]' \
+    "J[   524288 show s,t,P-debug (don't jump over) on opcodes within package DB]" \
+    'v[  1048576 verbose: use in conjunction with other flags]' \
+    'C[  2097152 copy-on-write]' \
+    'A[  4194304 consistency checks on internal structures]' \
+    'q[  8388608 quiet - currently only suppresses the "EXECUTING" message]' \
+    'M[ 16777216 trace smart match resolution]' \
+    'B[ 33554432 dump subroutine definitions, including special blocks like BEGIN]' \
+    'L[ 67108864 trace locale-related info]' \
+    'i[134217728 trace PerlIO layer processing]' \
+    'y[268435456 trace y///, tr/// compilation and execution]'
 }
 
 _perl "$@"




Messages sorted by: Reverse Date, Date, Thread, Author