Sunday, October 30, 2011

perl: indenting references (\@arr)

perl-code containing references intends stange.
For example:

<code>
while ($ok) {
if ($tbs) {
&show("step 1", \@arr, [24,60,60]);
&show("step 1", \@arr, [24,60,60]);
&show("step 1", \@arr, [24,60,60]);
&show("step 1", \@arr, [24,60,60]);
&show("step 1", \@arr, [24,60,60]);
&show("step 1", \@arr, [24,60,60]);
}
}
</code>

in /usr/share/vim/vim73/indent/perl.vim
I found 2 lines:
<code>
let bracepos = match(line, '[(){}\[\]]', match...
</code>
It seems as '[(){}\[\]]' finds brackets 'and' backslashes!

So I replaced these 2 lines with
<code>
let bracepos = BracePos(line, match...
</code>
and wrote a new function
<code>
" get position of () {} []
function! BracePos(line, start)
let l:min = strlen(a:line)+1

for l:char in split('(){}[]', '\zs')
let l:pos = match(a:line, l:char, a:start)
if l:pos >= 0
let l:min = min([l:min, l:pos])
endif
endfor

if l:min == strlen(a:line)+1
let l:min = -1
endif

return l:min
endfunction
</code>

Now it works fine.

I had checked it on my perl programs and it works for me.

--
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