Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Writing a Filter::Simple -based filter for .vim

by bbfu (Curate)
on Aug 15, 2003 at 19:19 UTC ( [id://284241]=note: print w/replies, xml ) Need Help??


in reply to Writing a Filter::Simple -based filter for .vim

Thinking about it some more, I believe that you're actually trying to do two things here: 1) Emulate the interface provided by VIM, and 2) Filter out VIM code from the Perl code, so that you can run .vim file directly under perl. These two are separate, and should be made into two distinct modules.

It should be fairly straight-forward to create a VIM::Emulate module. There's an overview of the VIM interface features you'd need to implement at :help perl-overview in VIM. The only one that I think wouldn't be feasable is the VIM::Eval() function, since you'd have to emulate every VIM command. If you felt ambitious, you could implement a "most commonly used" subset of the VIM commands, and detail it in the documentation for your module. If you do create this module, be sure to upload it to CPAN.

Filtering out the non-Perl code is a little more tricky. I think, however, that you'd be better off not using a Filter::Simple-based solution, and instead leverage perl's -x command-line option. Simply add a she-bang line to the start of the Perl code, and a __END__ line to the end of it, and pass the -x option to perl. You won't be able to have multiple Perl functions in one .vim file but it would be a lot less work on your part. Also, one way around that limitation would be to have one big Perl block in your .vim file that declares a bunch of functions, and then declare your VIM functions separately that just call the appropriate Perl function, like so:

perl <<EOP #!perl sub foo { VIM::Msg("Called foo"); } sub bar { VIM::Msg("Called bar"); } __END__ EOP func! TestFoo() " Note, you will need to pass along any " parameters your VIM function is called with. perl foo() endfu func! TestBar() perl bar() endfu

Anyway, I that's how I would approach this problem. Let me know if you decide to start working on a VIM::Emulate module. I would be willing to assist, whenever I have time.

bbfu
Black flowers blossom
Fearless on my breath

Replies are listed 'Best First'.
Re^2: Writing a Filter::Simple -based filter for .vim
by Intrepid (Deacon) on Aug 17, 2003 at 13:12 UTC
    Anyway, I that's how I would approach this problem. Let me know if you decide to start working on a VIM::Emulate module. I would be willing to assist, whenever I have time.

    Excellent! Thank you. I am quite short on time myself right now, so I'll have to keep this reply brief.

    One thing I'd like to mention is how great the insight you've provided is, regarding one issue. Your lattermost suggestions hinge on the understanding that Vim is creating a persistent perl interpreter that is lasting the lifetime of the Vim script: as far as I knew, it was not, and so it never occured to me to try to do this. I had thought that Vim creates an interpreter for each block of Perl code, it does its work and then expires. I was wrong!

    The example you posted above in fact proves out nicely, so thanks again for the very helpful insights. I'll be in touch!

        Soren/Intrepid

    -- 
    use PerlMonk::Tye qw(:wisely);
    

      Vim is creating a persistent perl interpreter that is lasting the lifetime of the Vim script

      Actually, the perl interpreter is lasting for the entire life of the VIM instance, as evidenced by the fact that you can declare Perl functions in one .vim script and call them in a different .vim script.

      This, of course, leads to the logical solution for the parsing-via-stand-alone-perl issue: move your functions into a module (or even just a required .pl script), and use the module in you .vim script. This would probably work out better in the long run than even in-lining Perl code in the .vim script and using the -x option, as you could then re-use the Perl code. Then, you'd need only create the VIM emulation module.

      bbfu
      Black flowers blossom
      Fearless on my breath

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://284241]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-25 04:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found