Skip to content

Commit 72bbe35

Browse files
committed
fixed folding for inline def statements
1 parent 2c6e898 commit 72bbe35

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

autoload/pymode/folding.vim

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ let s:def_regex = g:pymode_folding_regex
88
let s:blank_regex = '^\s*$'
99
" Spyder, a very popular IDE for python has a template which includes
1010
" '@author:' ; thus the regex below.
11-
let s:decorator_regex = '^\s*@\(author:\)\@!'
11+
let s:decorator_regex = '^\s*@\(author:\)\@!'
1212
let s:doc_begin_regex = '^\s*[uU]\=\%("""\|''''''\)'
1313
let s:doc_end_regex = '\%("""\|''''''\)\s*$'
1414
" This one is needed for the while loop to count for opening and closing
@@ -200,7 +200,7 @@ fun! s:BlockStart(lnum) "{{{
200200

201201
" Now find the class/def one shiftwidth lower than the start of the
202202
" aforementioned indent block.
203-
if next_stmt_at_def_indent && next_stmt_at_def_indent < a:lnum
203+
if next_stmt_at_def_indent && a:lnum <= next_stmt_at_def_indent
204204
let max_indent = max([indent(next_stmt_at_def_indent) - &shiftwidth, 0])
205205
else
206206
let max_indent = max([indent(prevnonblank(a:lnum)) - &shiftwidth, 0])
@@ -211,6 +211,14 @@ endfunction "}}}
211211
fun! s:BlockEnd(lnum) "{{{
212212
" Note: Make sure to reset cursor position after using this function.
213213
call cursor(a:lnum, 0)
214+
" Regex translation:
215+
" \v: very magic
216+
" \s: any space char
217+
" {...}: zero to more as many as possible
218+
" \S: non whitespace
219+
" index [0]: gets the line returned by searchpos
220+
" flag 'n': do not move cursor
221+
" flag 'W': don't wrap around the end of the file
214222
return searchpos('\v^\s{,'.indent('.').'}\S', 'nW')[0] - 1
215223
endfunction "}}}
216224

@@ -227,7 +235,7 @@ function! s:Is_opening_folding(lnum) "{{{
227235
for i in range(1, a:lnum)
228236
let i_line = getline(i)
229237

230-
if i_line =~ s:doc_line_regex
238+
if i_line =~ s:doc_line_regex
231239
" echom "case 00 on line " . i
232240
continue
233241
endif
@@ -252,7 +260,7 @@ function! s:Is_opening_folding(lnum) "{{{
252260
elseif i_line =~ s:doc_general_regex
253261
" echom "extra docstrings on line " . i
254262
let extra_docstrings = extra_docstrings + 1
255-
endif
263+
endif
256264
endfor
257265

258266
if fmod(number_of_folding, 2) == 1 "If odd then it is an opening

0 commit comments

Comments
 (0)