Python script based on this perl script

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Python script based on this perl script

Suresh Govindachar`
Hello,

  All I know about python is that it uses tabs as part of its
  syntax.  I am curious about it, and was wondering how one
  would translate the following "one line" perl based command
  into a python based command.  Please show me.
 
  command!  -bang Ls     redir @" | silent ls<bang> | redir END | echo "\n" |
                      \  perl {
                      \          my $foo=VIM::Eval('@"');
                      \          my %list=();
                      \          my $boo;
                      \          while($foo =~ m/(.*?line\s+\d+)/g)
                      \          {
                      \             $boo = $1;
                      \             $boo =~ m/"([^"]+)"/;
                      \             $list{$1} = $boo;
                      \          }
                      \          my $msg = "\n";
                      \          if ($^O =~ /mswin/i)
                      \          {
                      \             for $boo (sort { lc($a) cmp lc($b) } keys %list)
                      \             {
                      \                $msg .= "$list{$boo}\n";
                      \             }
                      \          }
                      \          else
                      \          {
                      \             for $boo (sort keys %list)
                      \             {
                      \                $msg .= "$list{$boo}\n";
                      \             }
                      \          }
                      \          VIM::Msg($msg);
                      \       }  
                      \  <cr>
 
 
  The preceding "single-line" command defines the
  user-command :Ls[!] whose output is the same as that
  of :ls but sorted by buffer name.  (However, unlike ls, Ls
  clobbers up the message-history.)

  (In another post with subject "Translate to Vim 7 script", I asked
  about translating an extremely identical one-liner to Vim script.
  The earlier version prints one line at a time, this one first
  collects all the lines into the variable $msg and then prints $msg.
  I worded the subject of this post in a manner so as to avoid
  confusing this thread with the other one.)

  Thanks,
 
  --Suresh