ftplugin: Avoid changing global viewoptions

As mentioned in an earlier commit, viewoptions is global, so it's
probably best to override it only temporarily for mkview.

(loadview is moved to autoload just for symmetry and in case we need to
do something more complex, like saving/restoring foldmethod, later)
This commit is contained in:
Tomas Janousek 2020-12-18 16:57:38 +00:00 committed by Tomas Babej
parent 7b72ee47b9
commit a6907bac85
2 changed files with 14 additions and 4 deletions

View file

@ -1,6 +1,18 @@
if exists('g:loaded_taskwiki_auto') | finish | endif if exists('g:loaded_taskwiki_auto') | finish | endif
let g:loaded_taskwiki_auto = 1 let g:loaded_taskwiki_auto = 1
function! taskwiki#MkView() abort
let viewoptions = &viewoptions
set viewoptions-=options
mkview
let &viewoptions = viewoptions
endfunction
function! taskwiki#LoadView() abort
silent! loadview
silent! doautocmd SessionLoadPost
endfunction
function! taskwiki#FoldInit() abort function! taskwiki#FoldInit() abort
" Unless vimwiki is configured to use its folding, set our own " Unless vimwiki is configured to use its folding, set our own
if &foldtext !~? 'VimwikiFold' if &foldtext !~? 'VimwikiFold'

View file

@ -41,10 +41,8 @@ augroup taskwiki
autocmd BufWrite <buffer> TaskWikiBufferSave autocmd BufWrite <buffer> TaskWikiBufferSave
" Save and load the view to preserve folding, if desired " Save and load the view to preserve folding, if desired
if !exists('g:taskwiki_dont_preserve_folds') if !exists('g:taskwiki_dont_preserve_folds')
setlocal viewoptions-=options autocmd BufWinLeave <buffer> call taskwiki#MkView()
autocmd BufWinLeave <buffer> mkview autocmd BufWinEnter <buffer> call taskwiki#LoadView()
autocmd BufWinEnter <buffer> silent! loadview
autocmd BufWinEnter <buffer> silent! doautocmd SessionLoadPost
endif endif
" Reset cache when switching buffers " Reset cache when switching buffers
execute "autocmd BufEnter <buffer> :" . g:taskwiki_py . "cache.load_current().reset()" execute "autocmd BufEnter <buffer> :" . g:taskwiki_py . "cache.load_current().reset()"