2
2
3
3
4
4
let s: blank_regex = ' ^\s*$'
5
- let s: def_regex = ' ^\s*\(class\|def\) \w\+'
5
+ let s: def_regex = ' ^\s*\%(class\|def\) \w\+'
6
+ let s: decorator_regex = ' ^\s*@'
7
+ let s: doc_begin_regex = ' ^\s*\%("""\|'''''' \)'
8
+ let s: doc_end_regex = ' \%("""\|'''''' \)\s*$'
9
+ let s: doc_line_regex = ' ^\s*\("""\|'''''' \).\+\1\s*$'
6
10
7
11
8
12
fun ! pymode#folding#text () " {{{
9
13
let fs = v: foldstart
10
- while getline (fs ) = ~ ' ^\s*@'
14
+ while getline (fs ) = ~ ' \%( ^\s*@\)\|\%(^\s*\%("""\| '''''' \)\s*$\) '
11
15
let fs = nextnonblank (fs + 1 )
12
16
endwhile
13
17
let line = getline (fs )
@@ -21,6 +25,7 @@ fun! pymode#folding#text() " {{{
21
25
let line = substitute (line , ' \t' , onetab, ' g' )
22
26
23
27
let line = strpart (line , 0 , windowwidth - 2 - len (foldedlinecount))
28
+ let line = substitute (line , ' \%("""\|'''''' \)' , ' ' , ' ' )
24
29
let fillcharcount = windowwidth - len (line ) - len (foldedlinecount)
25
30
return line . ' …' . repeat (" " ,fillcharcount) . foldedlinecount . ' …' . ' '
26
31
endfunction " }}}
@@ -30,21 +35,32 @@ fun! pymode#folding#expr(lnum) "{{{
30
35
31
36
let line = getline (a: lnum )
32
37
let indent = indent (a: lnum )
38
+ let prev_line = getline (a: lnum - 1 )
39
+
40
+ if line = ~ s: def_regex || line = ~ s: decorator_regex
41
+ if prev_line = ~ s: decorator_regex
42
+ return ' ='
43
+ else
44
+ return " >" .(indent / &shiftwidth + 1 )
45
+ endif
46
+ endif
33
47
34
- if line = ~ s: def_regex
35
- return " >" .(indent / &shiftwidth + 1 )
48
+ if line = ~ s: doc_begin_regex
49
+ \ && line !~ s: doc_line_regex
50
+ \ && prev_line = ~ s: def_regex
51
+ return " >" .(indent / &shiftwidth + 1 )
36
52
endif
37
53
38
- if line = ~ ' ^\s*@'
39
- return -1
54
+ if line = ~ s: doc_end_regex
55
+ \ && line !~ s: doc_line_regex
56
+ return " <" .(indent / &shiftwidth + 1 )
40
57
endif
41
58
42
59
if line = ~ s: blank_regex
43
- let prev_line = getline (a: lnum - 1 )
44
60
if prev_line = ~ s: blank_regex
45
61
return -1
46
62
else
47
- return foldlevel ( prevnonblank ( a: lnum ))
63
+ return ' = '
48
64
endif
49
65
endif
50
66
0 commit comments