From 94fe6ed8e897a705cfb4abd66c73a4a8e356eb30 Mon Sep 17 00:00:00 2001 From: Tomas Janousek Date: Mon, 8 Jun 2020 01:20:05 +0200 Subject: [PATCH] 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. --- ftplugin/vimwiki/taskwiki.vim | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ftplugin/vimwiki/taskwiki.vim b/ftplugin/vimwiki/taskwiki.vim index fa030c0..45c15ed 100644 --- a/ftplugin/vimwiki/taskwiki.vim +++ b/ftplugin/vimwiki/taskwiki.vim @@ -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! * " Update to TW upon saving @@ -44,6 +42,13 @@ augroup taskwiki autocmd BufWinEnter silent! doautocmd SessionLoadPost endif execute "autocmd BufEnter :" . 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 ++once :" . g:taskwiki_py . "WholeBuffer.update_from_tw()" + else + execute g:taskwiki_py . "WholeBuffer.update_from_tw()" + endif augroup END " Global update commands