zsh-workers
 help / color / mirror / code / Atom feed
From: "Jun T." <takimoto-j@kba.biglobe.ne.jp>
To: "zsh-workers@zsh.org" <zsh-workers@zsh.org>
Subject: Re: [Pkg-zsh-devel] Bug#679824: zsh: Buggy perl completion with -e [origin: vincent@vinc17.net]
Date: Mon, 30 Jun 2014 19:58:26 +0900	[thread overview]
Message-ID: <FC2BB00F-2E7B-4E4A-BFC8-0FE072B26ECB@kba.biglobe.ne.jp> (raw)
In-Reply-To: <20140628142003.GI5355@sym.noone.org>


On 2014/06/28, at 23:20, Axel Beckert <abe@deuxchevaux.org> wrote:
> $ perl -pi -e 's/foo/bar/' [TAB]
> 
> zsh wants to complete on Perl scripts instead of normal files.
> AFAIK, after -e '...', completion should be done on arbitrary
> arguments (e.g. like after an unknown command).

I first thought that just replacing the line 19 of _perl
    '(   -E)*-e+[run one line of program]:one line of program' \
by
    '(1   -E)*-e+[run one line of program]:one line of program' \
would be enough, but it didn't work. For example

    perl -e 's/foo/bar/' <TAB>

will offer all the command names (external commands etc.), instead of
the file names in the current directory.

This is because the '::' in line 44
    '*::args: _normal'
will clear the array $words, and the completion system thinks that
it is completing at the beginning of the command line and will try
to complete a command name.

But this '::' can't be simply replaced by ':' (infinite recursion
will happen).

A possible fix would be to modify the completion of the 1st argument
if -e '...' is already on the command line (see the patch bellow).
But detecting -e '...' (or -E '...') is rather complicated, because
perl allows command lines like

    perl -pes/foo/bar/ arg ...
    perl -CE script_file arg ...

I'm not sure the following patch is 100% OK (I'm not familiar with
most of the perl command line options).

Another possibility would be to modify line 19 (and 20) as above,
and modify line 44 to
    '*:args: _files'
I guess this may reduce the possibility of user customization of
the completion, but I have no idea how serious it is.


diff --git a/Completion/Unix/Command/_perl b/Completion/Unix/Command/_perl
index b00baa6..1939cb0 100644
--- a/Completion/Unix/Command/_perl
+++ b/Completion/Unix/Command/_perl
@@ -40,10 +40,21 @@ _perl () {
     "(-w    -X)-W[enable all warnings (ignores 'no warnings')]" \
     "(-w -W   )-X[disable all warnings (ignores 'use warnings')]" \
     '-x-[strip off text before #!perl line and perhaps cd to directory]:directory to cd to:_files -/' \
-    '1:Perl script:_files -/ -g "*.(p[ml]|PL|t)(-.)"' \
+    '1:script or args:_script_or_args' \
     '*::args: _normal'
 }
 
+_script_or_args () {
+  local expl
+  if (( $words[(I)-(e|E)*] )); then
+    _description args expl 'file'
+    _files "$expl[@]"
+  else
+    _description script expl 'Perl script'
+    _files "$expl[@]" -/ -g "*.(p[ml]|PL|t)(-.)"
+  fi
+}
+
 _perl_m_opt () {
   compset -P '-'
 




  reply	other threads:[~2014-06-30 11:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-28 14:20 Fwd: " Axel Beckert
2014-06-30 10:58 ` Jun T. [this message]
2014-06-30 13:02   ` Jun T.
2014-07-03 15:59     ` Jun T.
2014-07-03 16:11       ` Peter Stephenson
2014-07-03 16:42         ` Bart Schaefer
2014-07-06 21:58   ` Oliver Kiddle
2014-07-23 12:01     ` takimoto-j
2014-06-30 11:45 ` Jun T.
2014-06-30 19:09   ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=FC2BB00F-2E7B-4E4A-BFC8-0FE072B26ECB@kba.biglobe.ne.jp \
    --to=takimoto-j@kba.biglobe.ne.jp \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).