ftplugin: Postpone initial refresh to better preserve folds

Vim preserves folds by writing line jumps into the view script, so it's
better to load this script with the original file contents and only then
refresh from taskwarrior. The folding is still often broken when the
buffer is updated, but that can now be considered a vim bug and may
perhaps one day be fixed (or even worked around, if one is persistent
enough). Loading the view after modifying the buffer is simply wrong,
that can never ever work.
This commit is contained in:
Tomas Janousek 2020-06-08 01:20:05 +02:00 committed by Tomas Babej
parent f3fe7aca21
commit 94fe6ed8e8

View file

@ -31,8 +31,6 @@ if !exists("g:did_python_taskwiki")
let g:did_python_taskwiki = 1
endif
execute g:taskwiki_py . "WholeBuffer.update_from_tw()"
augroup taskwiki
autocmd! * <buffer>
" Update to TW upon saving
@ -44,6 +42,13 @@ augroup taskwiki
autocmd BufWinEnter <buffer> silent! doautocmd SessionLoadPost
endif
execute "autocmd BufEnter <buffer> :" . g:taskwiki_py . "cache.load_current().reset()"
" Refresh on load (if possible, after loadview to preserve folds)
if has('patch-8.1.1113') || has('nvim-0.4.0')
execute "autocmd BufWinEnter <buffer> ++once :" . g:taskwiki_py . "WholeBuffer.update_from_tw()"
else
execute g:taskwiki_py . "WholeBuffer.update_from_tw()"
endif
augroup END
" Global update commands