From f125d0bc8b08cbb9e77bd1b64e189909821239d1 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 7 Jul 2018 14:34:55 +1200 Subject: Rearrange heredoc/POD indent check for speed --- vim/indent/perl.vim | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'vim/indent') diff --git a/vim/indent/perl.vim b/vim/indent/perl.vim index f02f2a65..14a211f5 100644 --- a/vim/indent/perl.vim +++ b/vim/indent/perl.vim @@ -35,31 +35,32 @@ function! GetPerlIndent(lnum) return 0 endif - " Heredoc and POD detection; start at top of buffer + " Heredoc and POD detection; this is expensive, so limit it to 512 lines of + " context + let l:lim = 512 + let l:hpn = line('$') > l:lim + \ ? line('$') - l:lim + \ : 0 let l:pod = 0 - let l:hpn = 0 while l:hpn < a:lnum let l:hpl = getline(l:hpn) " If we're not in a heredoc and not in a comment ... if !exists('l:hpw') && l:hpl !~# '^\s*#' - " POD switching - if !l:pod && stridx(l:hpl, '=pod') == 0 + " POD switching; match any section so that we can handle long PODs + if !l:pod && l:hpl =~# '^=\l\+\d\?\>' let l:pod = 1 elseif l:pod && stridx(l:hpl, '=cut') == 0 let l:pod = 0 - else - " Line opens with a heredoc + " Heredoc switch on + else let l:hpm = matchstr(l:hpl, s:heredoc_open) - - " Store the heredoc word and make this our indent reference if strlen(l:hpm) let l:hpw = matchstr(l:hpm, s:heredoc_word) let l:pn = l:hpn endif - endif " If we are in a heredoc and we found the token word, finish it -- cgit v1.2.3