Save and restore fdm on undo

This commit is contained in:
Karl Yngve Lervåg 2013-10-15 10:19:00 +02:00
parent 76b2c9f27f
commit e2ed3dd8c6

View File

@ -10,6 +10,11 @@ function! latex#fold#init(initialized)
nnoremap <silent><buffer> zx :call latex#fold#refresh()<cr>zx nnoremap <silent><buffer> zx :call latex#fold#refresh()<cr>zx
endif endif
"
" For some reason, foldmethod=expr makes undo slow (at least in some cases)
"
nnoremap <silent><buffer> u :call FdmSave()<cr>u:call FdmRestore()<cr>
" "
" The foldexpr function returns "=" for most lines, which means it can " The foldexpr function returns "=" for most lines, which means it can
" become slow for large files. The following is a hack that is based on " become slow for large files. The following is a hack that is based on
@ -19,8 +24,8 @@ function! latex#fold#init(initialized)
if !a:initialized if !a:initialized
augroup latex_fold augroup latex_fold
autocmd! autocmd!
autocmd InsertEnter *.tex call s:fdm_save() autocmd InsertEnter *.tex call FdmSave()
autocmd InsertLeave *.tex call s:fdm_restore() autocmd InsertLeave *.tex call FdmRestore()
augroup END augroup END
endif endif
endif endif
@ -163,21 +168,22 @@ function! latex#fold#text()
endfunction endfunction
" }}}1 " }}}1
" {{{1 s:notbslash and s:notcomment " {{{1 FdmRestore
let s:notbslash = '\%(\\\@<!\%(\\\\\)*\)\@<=' function! FdmRestore()
let s:notcomment = '\%(\%(\\\@<!\%(\\\\\)*\)\@<=%.*\)\@<!'
" {{{1 s:fdm_restore
function! s:fdm_restore()
let &l:foldmethod = s:fdm let &l:foldmethod = s:fdm
endfunction endfunction
" {{{1 s:fdm_save " {{{1 FdmSave
let s:fdm='' let s:fdm=''
function! s:fdm_save() function! FdmSave()
let s:fdm = &l:foldmethod let s:fdm = &l:foldmethod
setlocal foldmethod=manual setlocal foldmethod=manual
endfunction endfunction
" }}}1
" {{{1 s:notbslash and s:notcomment
let s:notbslash = '\%(\\\@<!\%(\\\\\)*\)\@<='
let s:notcomment = '\%(\%(\\\@<!\%(\\\\\)*\)\@<=%.*\)\@<!'
" {{{1 s:find_fold_sections " {{{1 s:find_fold_sections
function! s:find_fold_sections() function! s:find_fold_sections()