Skip to content

Commit 04948cf

Browse files
committed
Merge pull request python-mode#207 from alvinfrancis/develop
Modify folding
2 parents b20f3ce + 96491ce commit 04948cf

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

autoload/pymode/folding.vim

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33

44
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*$'
610

711

812
fun! pymode#folding#text() " {{{
913
let fs = v:foldstart
10-
while getline(fs) =~ '^\s*@'
14+
while getline(fs) =~ '\%(^\s*@\)\|\%(^\s*\%("""\|''''''\)\s*$\)'
1115
let fs = nextnonblank(fs + 1)
1216
endwhile
1317
let line = getline(fs)
@@ -21,6 +25,7 @@ fun! pymode#folding#text() " {{{
2125
let line = substitute(line, '\t', onetab, 'g')
2226

2327
let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount))
28+
let line = substitute(line, '\%("""\|''''''\)', '', '')
2429
let fillcharcount = windowwidth - len(line) - len(foldedlinecount)
2530
return line . '' . repeat(" ",fillcharcount) . foldedlinecount . '' . ' '
2631
endfunction "}}}
@@ -30,21 +35,32 @@ fun! pymode#folding#expr(lnum) "{{{
3035

3136
let line = getline(a:lnum)
3237
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
3347

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)
3652
endif
3753

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)
4057
endif
4158

4259
if line =~ s:blank_regex
43-
let prev_line = getline(a:lnum - 1)
4460
if prev_line =~ s:blank_regex
4561
return -1
4662
else
47-
return foldlevel(prevnonblank(a:lnum))
63+
return '='
4864
endif
4965
endif
5066

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy