-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfolding.vim
More file actions
46 lines (37 loc) · 982 Bytes
/
Copy pathfolding.vim
File metadata and controls
46 lines (37 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
" slightly modified code sample from the:
" http://learnvimscriptthehardway.stevelosh.com/chapters/49.html
setlocal foldmethod=expr
setlocal foldexpr=GetPythonFold(v:lnum)
fun! s:NextNonBlankLine(lnum)"{{{
let numlines = line('$')
let current = a:lnum + 1
while current <= numlines
if getline(current) =~? '\v\S'
return current
endif
let current += 1
endwhile
return -2
endfun
"}}}
fun! s:IndentLevel(lnum)"{{{
return indent(a:lnum) / &shiftwidth
endfun
"}}}
fun! GetPythonFold(lnum)"{{{
if getline(a:lnum) =~? '\v^\s*$'
" '=' = fold blanks, '-1' = don't fold blanks
return '='
endif
let this_indent = <SID>IndentLevel(a:lnum)
let next_indent = <SID>IndentLevel(<SID>NextNonBlankLine(a:lnum))
if next_indent == this_indent
return this_indent
elseif next_indent < this_indent
return this_indent
elseif next_indent > this_indent
return '>' . next_indent
endif
endfun
"}}}
" vim: set sw=2 sts=2 et fdm=marker: