zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: completing perl record separators
@ 2021-05-29 21:59 Oliver Kiddle
  2021-05-29 23:24 ` Bart Schaefer
  2021-05-30 12:48 ` Daniel Shahaf
  0 siblings, 2 replies; 5+ messages in thread
From: Oliver Kiddle @ 2021-05-29 21:59 UTC (permalink / raw)
  To: Zsh workers

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@spiers.net>
-#
-# 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 "$@"


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: completing perl record separators
  2021-05-29 21:59 PATCH: completing perl record separators Oliver Kiddle
@ 2021-05-29 23:24 ` Bart Schaefer
  2021-05-30  0:11   ` Oliver Kiddle
  2021-05-30 12:48 ` Daniel Shahaf
  1 sibling, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2021-05-29 23:24 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: Zsh workers

On Sat, May 29, 2021 at 3:00 PM Oliver Kiddle <opk@zsh.org> wrote:
>
> 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.

Hmm, Adam may precede the git history.  The farthest back it goes is
to Sven reorganizing the file hierarchy.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: completing perl record separators
  2021-05-29 23:24 ` Bart Schaefer
@ 2021-05-30  0:11   ` Oliver Kiddle
  2021-05-30 17:42     ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Oliver Kiddle @ 2021-05-30  0:11 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh workers

Bart Schaefer wrote:
> On Sat, May 29, 2021 at 3:00 PM Oliver Kiddle <opk@zsh.org> wrote:
> >
> > 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.
>
> Hmm, Adam may precede the git history.  The farthest back it goes is
> to Sven reorganizing the file hierarchy.

Is this an objection or just entertaining pedantry about the limitations
of my general comment as applied to this case? Attributing credit can be
important, I'm just not especially fond of it in this form.

The --follow option ought to track beyond the reorganisation but as that
was done in CVS it has likely been too obscured. The commit message does
point to Completion/User/_perl and you can do
  git log -- Completion/User/_perl
The first version there is still the initial CVS import. So you'd have to
look at the content to see the comment. Or refer the mailing list
archives - which is the only option for nearly all other functions that
predate our use of CVS. (and rather more than we have for everything
predating the list archives)

Oliver


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: completing perl record separators
  2021-05-29 21:59 PATCH: completing perl record separators Oliver Kiddle
  2021-05-29 23:24 ` Bart Schaefer
@ 2021-05-30 12:48 ` Daniel Shahaf
  1 sibling, 0 replies; 5+ messages in thread
From: Daniel Shahaf @ 2021-05-30 12:48 UTC (permalink / raw)
  To: zsh-workers

Oliver Kiddle wrote on Sat, 29 May 2021 21:59 +00:00:
> 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.

Indeed it is:

% print -rl -- '"foo bar"' '' 'baz' | xargs  
foo bar baz
% print -rl -- '"foo bar"' '' 'baz' | perl -012l040pe1; echo
"foo bar"  baz 
%

Not bad for a one-byte program :-)

Cheers,

Daniel
(The final «1» is the only byte of Perl source code in that invocation;
it's the argument to the «-e» flag.)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: completing perl record separators
  2021-05-30  0:11   ` Oliver Kiddle
@ 2021-05-30 17:42     ` Bart Schaefer
  0 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2021-05-30 17:42 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: Zsh workers

On Sat, May 29, 2021 at 5:11 PM Oliver Kiddle <opk@zsh.org> wrote:
>
> Bart Schaefer wrote:
> > Hmm, Adam may precede the git history.
>
> Is this an objection or just entertaining pedantry about the limitations
> of my general comment as applied to this case?

Neither, really; it was just intended to alert you to consequences you
may not have considered, and then let you decide, which you have.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-05-30 17:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-29 21:59 PATCH: completing perl record separators Oliver Kiddle
2021-05-29 23:24 ` Bart Schaefer
2021-05-30  0:11   ` Oliver Kiddle
2021-05-30 17:42     ` Bart Schaefer
2021-05-30 12:48 ` Daniel Shahaf

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).