Tuesday, February 1, 2011

Vim, Perl and stuff.

I have a problem and a couple of optimizations I'd like to get some
help with if I could.

I have the following in my '.vim/after/ftplugin/perl.vim' file:

--8<---------------------------------------------------------
if ! exists("g:did_perl_statusline")
setlocal statusline+=%(\ %{StatusLineIndexLine()}%)
let g:did_perl_statusline = 1
endif

if has( 'perl' )
perl << EOP
use strict;

eval "use PPIx::IndexLines";
my $error = $@;

sub index_line {

if ( $error ) {

VIM::DoCommand "let subName='$error'";

} else {

my $curwin = $main::curwin;
my $curbuf = $main::curbuf;

# There's got to be a better way to slurp in the current buffer!
my $document = join "\n", $curbuf->Get( 1 .. $curbuf->Count );

my $ppi = PPIx::IndexLines->new( \$document );
$ppi->index_lines;
( my $line, undef ) = $curwin->Cursor;
my $sub_name = $ppi->line_type( $line );
VIM::DoCommand "let subName='$sub_name'";

}
}

EOP

function! StatusLineIndexLine()
perl index_line()
return subName
endfunction
endif
--->8--------------------------------------------------------

The problem is with the 'did_perl_statusline' if construct. If I have
this in place, then only the first perl file loaded will have the
output appended to the status line. If I don't include the if
construct then each time I switch back to any buffer with a perl file
the statusline will be appended to again, so eventually I'll end up
with something like

/some/perlfile.pl somesub somesub somesub somesub

I can't figure out how to get around this. Any ideas?

The line where I grab the lines of the buffer are very inefficient,
especially for a large file. Is there any way to access the contents
of the entire buffer besides looping through each one?

I know I can set this up so that the sub is only called when the file
is saved or read via the autocmd bufreadpost and bufwritepost options,
but that would mean the information being displayed would be out of
date when editing a file, especially when creating new code. I don't
know how else I can make this better though. Any ideas?
--
Alan Young

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment