develooper Front page | perl.fwp | Postings from April 2003

More Fun with Perl

From:
fwp
Date:
April 10, 2003 12:25
Subject:
More Fun with Perl
Message ID:
20030410191839.GB24090@pimlott.net
Go Simon.

I was extending the editor in Perl, and got tired of writing out

    VIM::DoCommand "...";

every time I wanted to run an editor command.  Why not use something
like the editor's native syntax?

    sub in_scratch_window (&)
    {
        my ($sub) = @_;
        my $width = VIM::Eval("winwidth(winnr())");
        :leftabove vsplit
        my $ret = $sub->();
        :hide
        :vertical resize $width
        $ret;
    }

Much better!

There isn't any trick to this, so I won't hold out on the
implementation, but I will leave some whitespace.

Andrew















     ^
     |
(whitespace)
     |
     v















use Filter::Util::Call;
BEGIN {
    filter_add( sub {
        my $status = filter_read;
        return $status unless /^\s*:/;
        s/"/\\"/g;
        s/^\s*:(.*)/VIM::DoCommand "$1";/;
        return $status;
    })
}



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About