Workaround for slow folding methods (issue #225)

This commit is contained in:
mMontu 2016-07-12 11:41:44 -03:00
parent 3f66117894
commit 777569f95f
2 changed files with 13 additions and 3 deletions

View File

@ -2288,6 +2288,8 @@ Limitations:
- 'list' is intended to work with lists nicely indented with 'shiftwidth'. - 'list' is intended to work with lists nicely indented with 'shiftwidth'.
- 'syntax' is only available for the default syntax so far. - 'syntax' is only available for the default syntax so far.
The options above can be suffixed with ':quick' (e.g.: 'expr:quick') in order
to use some workarounds to make folds work faster.
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*g:vimwiki_list_ignore_newline* *g:vimwiki_list_ignore_newline*

View File

@ -156,15 +156,15 @@ function! s:setup_buffer_enter() "{{{
" Settings foldmethod, foldexpr and foldtext are local to window. Thus in a " Settings foldmethod, foldexpr and foldtext are local to window. Thus in a
" new tab with the same buffer folding is reset to vim defaults. So we " new tab with the same buffer folding is reset to vim defaults. So we
" insist vimwiki folding here. " insist vimwiki folding here.
if g:vimwiki_folding ==? 'expr' if g:vimwiki_folding =~? '^expr.*'
setlocal fdm=expr setlocal fdm=expr
setlocal foldexpr=VimwikiFoldLevel(v:lnum) setlocal foldexpr=VimwikiFoldLevel(v:lnum)
setlocal foldtext=VimwikiFoldText() setlocal foldtext=VimwikiFoldText()
elseif g:vimwiki_folding ==? 'list' || g:vimwiki_folding ==? 'lists' elseif g:vimwiki_folding =~? '^list.*' || g:vimwiki_folding ==? '^lists.*'
setlocal fdm=expr setlocal fdm=expr
setlocal foldexpr=VimwikiFoldListLevel(v:lnum) setlocal foldexpr=VimwikiFoldListLevel(v:lnum)
setlocal foldtext=VimwikiFoldText() setlocal foldtext=VimwikiFoldText()
elseif g:vimwiki_folding ==? 'syntax' elseif g:vimwiki_folding =~? '^syntax.*'
setlocal fdm=syntax setlocal fdm=syntax
setlocal foldtext=VimwikiFoldText() setlocal foldtext=VimwikiFoldText()
else else
@ -446,6 +446,14 @@ augroup vimwiki
exe 'autocmd InsertLeave *'.s:ext.' call vimwiki#tbl#format(line("."))' exe 'autocmd InsertLeave *'.s:ext.' call vimwiki#tbl#format(line("."))'
exe 'autocmd InsertEnter *'.s:ext.' call vimwiki#tbl#reset_tw(line("."))' exe 'autocmd InsertEnter *'.s:ext.' call vimwiki#tbl#reset_tw(line("."))'
endif endif
if g:vimwiki_folding =~? ':quick$'
" from http://vim.wikia.com/wiki/Keep_folds_closed_while_inserting_text
" Don't screw up folds when inserting text that might affect them, until
" leaving insert mode. Foldmethod is local to the window. Protect against
" screwing up folding when switching between windows.
exe 'autocmd InsertEnter *'.s:ext.' if !exists("w:last_fdm") | let w:last_fdm=&foldmethod | setlocal foldmethod=manual | endif'
exe 'autocmd InsertLeave,WinLeave *'.s:ext.' if exists("w:last_fdm") | let &l:foldmethod=w:last_fdm | unlet w:last_fdm | endif'
endif
endfor endfor
augroup END augroup END
"}}} "}}}