Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fce811d

Browse files
committed
Add folding support for multi-line decorators
1 parent 7c8b25a commit fce811d

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

autoload/pymode/folding.vim

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ endif
1515

1616
fun! pymode#folding#text() " {{{
1717
let fs = v:foldstart
18-
while getline(fs) =~ '\%(^\s*@\)\|\%(^\s*\%("""\|''''''\)\s*$\)'
18+
while getline(fs) !~ s:def_regex && getline(fs) !~ s:doc_begin_regex
1919
let fs = nextnonblank(fs + 1)
2020
endwhile
21+
if getline(fs) =~ s:doc_begin_regex
22+
let fs = nextnonblank(fs + 1)
23+
endif
2124
let line = getline(fs)
2225

2326
let nucolwidth = &fdc + &number * &numberwidth
@@ -41,8 +44,24 @@ fun! pymode#folding#expr(lnum) "{{{
4144
let indent = indent(a:lnum)
4245
let prev_line = getline(a:lnum - 1)
4346

44-
if line =~ s:def_regex || line =~ s:decorator_regex
45-
if prev_line =~ s:decorator_regex
47+
if line =~ s:decorator_regex
48+
return ">".(indent / &shiftwidth + 1)
49+
endif
50+
51+
if line =~ s:def_regex
52+
" Check if last decorator is before the last def
53+
let decorated = 0
54+
let lnum = a:lnum - 1
55+
while lnum > 0
56+
if getline(lnum) =~ s:def_regex
57+
break
58+
elseif getline(lnum) =~ s:decorator_regex
59+
let decorated = 1
60+
break
61+
endif
62+
let lnum -= 1
63+
endwhile
64+
if decorated
4665
return '='
4766
else
4867
return ">".(indent / &shiftwidth + 1)

0 commit comments

Comments
 (0)