Add support for folding python blocks in vim files

This commit is contained in:
Kenneth Benzie 2016-09-11 13:02:20 +01:00
parent eedd83788f
commit bfd6df1d06

View File

@ -9,6 +9,17 @@ setlocal foldexpr=VimFold(v:lnum)
function! VimFold(lnum)
let l:line = getline(a:lnum)
if l:line =~ '^python\s\+<<\s\+\w\+\s*$'
let b:vim_python_end = substitute(l:line, '^python\s\+<<\s\+\(\w\+\)\s*$', '\1', '')
return 'a1'
endif
if exists('b:vim_python_end')
if l:line =~ '^'.b:vim_python_end.'\s*$'
unlet b:vim_python_end
return 's1'
endif
else
if l:line =~ '^\s*fun\(c\(tion\)\=\)\=!\=\s\+.*#\=\w*(.*).*$'
\ || l:line =~ '^\s*if\s*.*$'
\ || l:line =~ '^\s*el\(se\)\=\s*.*$'
@ -18,16 +29,15 @@ function! VimFold(lnum)
\ || l:line =~ '^\s*try\s*$'
\ || l:line =~ '^\s*cat\(ch\)\=\s*.*$'
\ || l:line =~ '^\s*fina\(lly\)\=\s*$'
\ || l:line =~ '\s*".*{{{\s*$'
return '>'.string((indent(a:lnum) / &shiftwidth) + 1)
elseif l:line =~ '^\s*endfun\(c\(tion\)\=\)\=\s*$'
\ || l:line =~ '^\s*en\(dif\)\=\s*$'
\ || l:line =~ '^\s*endw\(hile\)\=\s*$'
\ || l:line =~ '^\s*endfor\=\s*$'
\ || l:line =~ '^\s*endt\(ry\)\=\s*$'
\ || l:line =~ '\s*".*}}}\s*$'
return '<'.string((indent(a:lnum) / &shiftwidth) + 1)
endif
endif
return '='
endfunction