From f4b2a03625680ad27a3bc77ccec358582aee9094 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Thu, 3 Jun 2021 00:12:54 +0200 Subject: 48952: expand octal codes for record separators in perl completion --- Completion/Unix/Command/_perl | 99 ++++++++++++++++++++++++++----------------- 1 file changed, 60 insertions(+), 39 deletions(-) (limited to 'Completion/Unix/Command') 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 -# -# 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 res