@@ -216,6 +216,15 @@ endfunction "}}}
216
216
217
217
function ! s: Is_opening_folding (lnum)" {{{
218
218
" Helper function to see if docstring is opening or closing
219
+
220
+ " Cache the result so the loop runs only once per change
221
+ if get (b: ,' fold_changenr' ,-1 )== changenr ()
222
+ return b: fold_cache [a: lnum ]" If odd then it is an opening
223
+ else
224
+ let b: fold_changenr= changenr ()
225
+ let b: fold_cache= []
226
+ endif
227
+
219
228
let number_of_folding= 0 " To be analized if odd/even to inform if it is opening or closing.
220
229
let has_open_docstring= 0 " To inform is already has an open docstring.
221
230
let extra_docstrings= 0 " To help skipping ''' and" " " which are not docstrings
@@ -224,7 +233,9 @@ function! s:Is_opening_folding(lnum) "{{{
224
233
" not just triple quotes (that could be a regular string).
225
234
"
226
235
" Iterater over all lines from the start until current line (inclusive)
227
- for i in range (1 ,a: lnum )
236
+ for i in range (1 ,line (' $' ))
237
+ call add (b: fold_cache , number_of_folding% 2 )
238
+
228
239
let i_line= getline (i )
229
240
230
241
if i_line= ~s: doc_line_regex
@@ -255,11 +266,9 @@ function! s:Is_opening_folding(lnum) "{{{
255
266
endif
256
267
endfor
257
268
258
- if fmod (number_of_folding,2 )== 1 " If odd then it is an opening
259
- return 1
260
- else
261
- return 0
262
- endif
269
+ call add (b: fold_cache , number_of_folding% 2 )
270
+
271
+ return b: fold_cache [a: lnum ]
263
272
endfunction " }}}
264
273
265
274
" vim:fdm = marker:fdl = 0