forked from python-mode/python-mode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfolding.vim
More file actions
80 lines (61 loc) · 2.15 KB
/
folding.vim
File metadata and controls
80 lines (61 loc) · 2.15 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
" Python-mode folding functions
let s:def_regex = g:pymode_folding_regex
let s:blank_regex = '^\s*$'
let s:decorator_regex = '^\s*@'
let s:doc_begin_regex = '^\s*\%("""\|''''''\)'
let s:doc_end_regex = '\%("""\|''''''\)\s*$'
let s:doc_line_regex = '^\s*\("""\|''''''\).\+\1\s*$'
let s:symbol = matchstr(&fillchars, 'fold:\zs.') " handles multibyte characters
if s:symbol == ''
let s:symbol = ' '
endif
fun! pymode#folding#text() " {{{
let fs = v:foldstart
while getline(fs) =~ '\%(^\s*@\)\|\%(^\s*\%("""\|''''''\)\s*$\)'
let fs = nextnonblank(fs + 1)
endwhile
let line = getline(fs)
let nucolwidth = &fdc + &number * &numberwidth
let windowwidth = winwidth(0) - nucolwidth - 6
let foldedlinecount = v:foldend - v:foldstart
" expand tabs into spaces
let onetab = strpart(' ', 0, &tabstop)
let line = substitute(line, '\t', onetab, 'g')
let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount))
let line = substitute(line, '\%("""\|''''''\)', '', '')
let fillcharcount = windowwidth - len(line) - len(foldedlinecount) + 1
return line . ' ' . repeat(s:symbol, fillcharcount) . ' ' . foldedlinecount
endfunction "}}}
fun! pymode#folding#expr(lnum) "{{{
let line = getline(a:lnum)
let indent = indent(a:lnum)
let prev_line = getline(a:lnum - 1)
if line =~ s:def_regex || line =~ s:decorator_regex
if prev_line =~ s:decorator_regex
return '='
else
return ">".(indent / &shiftwidth + 1)
endif
endif
if line =~ s:doc_begin_regex && line !~ s:doc_line_regex && prev_line =~ s:def_regex
return ">".(indent / &shiftwidth + 1)
endif
if line =~ s:doc_end_regex && line !~ s:doc_line_regex
return "<".(indent / &shiftwidth + 1)
endif
if line =~ s:blank_regex
if prev_line =~ s:blank_regex
if indent(a:lnum + 1) == 0 && getline(a:lnum + 1) !~ s:blank_regex
return 0
endif
return -1
else
return '='
endif
endif
if indent == 0
return 0
endif
return '='
endfunction "}}}
" vim: fdm=marker:fdl=0