package VimFilter; use FindBin qw($RealBin $RealScript); use Carp; BEGIN { $|++; #-------------------------------------------------------------------- # some code d/l from Perl Monks node: 106194 # View Original: http://www.perlmonks.org/?node=106194&displaytype=displaycode #-------------------------------------------------------------------- use Term::Cap; use POSIX; my $termios = new POSIX::Termios; $termios->getattr; my $ospeed = $termios->getospeed; my $t = Tgetent Term::Cap { TERM => undef, OSPEED => $ospeed }; ($NO, $BO, $US, $SO) = map { $t->Tputs($_,1) } qw/me md us so/; # ended borrowed code. $BO = $US; our ($Supplied_dummy, $VFD); open US , "< $RealBin/$RealScript" or croak "Cannot open() \"$RealScript\" in \"$RealBin\", $!"; local $/; undef $/; my $whole = ; close US or die "Went wrong close() ing, $!"; print STDERR "Magnitude scalar of file is ",length $whole, "\n"; if( $whole =~m/^(?:#NOVIM#)?\s*my\s*\(?\s*\@(\w*Dummy\w*)\s*\)?\s*=.+?(?=;\n)/msi ) { $Supplied_dummy = $&; $VFD = $1; $Supplied_dummy =~s/^#NOVIM#//; } else { croak "\nCouldn't find a ${BO}\@Dummy${NO} declaration in your file:\n", "${RealBin}/${RealScript}\n"; } print STDERR "We found your ${BO}\$Dummy${NO} declaration:", < 0x0;') { s'#NOVIM#''g; s'\A\s*fun?c?t?i?o?n?!?\s+.*''m ; s[^\s*\Qperl <<\E.*] [$dumEv]m ; s'VIM::Msg'print STDERR 'mg ; s'VIM::Eval\s*\('&$dummyEval('mg ; s/\$ curbuf->(?:G|S)et\( ([^\)]+) \)/\$${VFD}[$1] /xg ; s/\$ curbuf->Count\(\) /scalar(\@${VFD})/xg ; s'\$ curbuf-> \w+ \(\) 'qq/DUMMY/'exg ; } } ; 1; =pod =head1 SYNOPSIS use VimFilter; =head1 NOTES The entire source file is slurped in as one long string. The sub{} is not applied line-wise (looping through each line) but to the whole file, once. Trying to define a token to "ignore from here down" as suggestion in the docs for Filter::Simple didn't work. I probably didn't understand something about how to do that. The biggest challenge is to provide some kind of dummy array for the built-in automatic $curbuf object; we need to tailor that simulation to each application of this module. A real refinement would be to treat each substitution as a replaceable parameter, perhaps read in from a .conf file. One can even imagine a repository for those subregexen because the possible permutations are infinite! Using an external file would be the only rational approach. =cut