Add support for folding python blocks in vim files
This commit is contained in:
parent
eedd83788f
commit
bfd6df1d06
@ -9,24 +9,34 @@ setlocal foldexpr=VimFold(v:lnum)
|
|||||||
function! VimFold(lnum)
|
function! VimFold(lnum)
|
||||||
let l:line = getline(a:lnum)
|
let l:line = getline(a:lnum)
|
||||||
|
|
||||||
if l:line =~ '^\s*fun\(c\(tion\)\=\)\=!\=\s\+.*#\=\w*(.*).*$'
|
if l:line =~ '^python\s\+<<\s\+\w\+\s*$'
|
||||||
\ || l:line =~ '^\s*if\s*.*$'
|
let b:vim_python_end = substitute(l:line, '^python\s\+<<\s\+\(\w\+\)\s*$', '\1', '')
|
||||||
\ || l:line =~ '^\s*el\(se\)\=\s*.*$'
|
return 'a1'
|
||||||
\ || l:line =~ '^\s*elseif\=\s*.*$'
|
endif
|
||||||
\ || l:line =~ '^\s*wh\(ile\)\=\s*.*$'
|
|
||||||
\ || l:line =~ '^\s*for\s*.*$'
|
if exists('b:vim_python_end')
|
||||||
\ || l:line =~ '^\s*try\s*$'
|
if l:line =~ '^'.b:vim_python_end.'\s*$'
|
||||||
\ || l:line =~ '^\s*cat\(ch\)\=\s*.*$'
|
unlet b:vim_python_end
|
||||||
\ || l:line =~ '^\s*fina\(lly\)\=\s*$'
|
return 's1'
|
||||||
\ || l:line =~ '\s*".*{{{\s*$'
|
endif
|
||||||
return '>'.string((indent(a:lnum) / &shiftwidth) + 1)
|
else
|
||||||
elseif l:line =~ '^\s*endfun\(c\(tion\)\=\)\=\s*$'
|
if l:line =~ '^\s*fun\(c\(tion\)\=\)\=!\=\s\+.*#\=\w*(.*).*$'
|
||||||
\ || l:line =~ '^\s*en\(dif\)\=\s*$'
|
\ || l:line =~ '^\s*if\s*.*$'
|
||||||
\ || l:line =~ '^\s*endw\(hile\)\=\s*$'
|
\ || l:line =~ '^\s*el\(se\)\=\s*.*$'
|
||||||
\ || l:line =~ '^\s*endfor\=\s*$'
|
\ || l:line =~ '^\s*elseif\=\s*.*$'
|
||||||
\ || l:line =~ '^\s*endt\(ry\)\=\s*$'
|
\ || l:line =~ '^\s*wh\(ile\)\=\s*.*$'
|
||||||
\ || l:line =~ '\s*".*}}}\s*$'
|
\ || l:line =~ '^\s*for\s*.*$'
|
||||||
return '<'.string((indent(a:lnum) / &shiftwidth) + 1)
|
\ || l:line =~ '^\s*try\s*$'
|
||||||
|
\ || l:line =~ '^\s*cat\(ch\)\=\s*.*$'
|
||||||
|
\ || l:line =~ '^\s*fina\(lly\)\=\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*$'
|
||||||
|
return '<'.string((indent(a:lnum) / &shiftwidth) + 1)
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return '='
|
return '='
|
||||||
|
Loading…
x
Reference in New Issue
Block a user