Skip to content

Make folding much faster in some cases #743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions autoload/pymode/folding.vim
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,15 @@ endfunction "}}}

function! s:Is_opening_folding(lnum) "{{{
" Helper function to see if docstring is opening or closing

" Cache the result so the loop runs only once per change
if get(b:, 'fold_changenr', -1) == changenr()
return b:fold_cache[a:lnum] "If odd then it is an opening
else
let b:fold_changenr = changenr()
let b:fold_cache = []
endif

let number_of_folding = 0 " To be analized if odd/even to inform if it is opening or closing.
let has_open_docstring = 0 " To inform is already has an open docstring.
let extra_docstrings = 0 " To help skipping ''' and """ which are not docstrings
Expand All @@ -224,7 +233,9 @@ function! s:Is_opening_folding(lnum) "{{{
" not just triple quotes (that could be a regular string).
"
" Iterater over all lines from the start until current line (inclusive)
for i in range(1, a:lnum)
for i in range(1, line('$'))
call add(b:fold_cache, number_of_folding % 2)

let i_line = getline(i)

if i_line =~ s:doc_line_regex
Expand Down Expand Up @@ -255,11 +266,9 @@ function! s:Is_opening_folding(lnum) "{{{
endif
endfor

if fmod(number_of_folding, 2) == 1 "If odd then it is an opening
return 1
else
return 0
endif
call add(b:fold_cache, number_of_folding % 2)

return b:fold_cache[a:lnum]
endfunction "}}}

" vim: fdm=marker:fdl=0