From 75cdb17d99330d0af295c449ef3c6850e327abd5 Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Tue, 8 Dec 2015 23:47:15 +0100 Subject: [PATCH] Use :mkview for restoring manual folds --- autoload/sy/fold.vim | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/autoload/sy/fold.vim b/autoload/sy/fold.vim index 7490267..e915bd7 100644 --- a/autoload/sy/fold.vim +++ b/autoload/sy/fold.vim @@ -53,17 +53,26 @@ endfunction " Function: #disable {{{1 function! sy#fold#disable() abort - let &l:foldmethod = w:sy_fdm - normal! zO + let &l:foldmethod = w:sy_folded.method + let &l:foldtext = w:sy_folded.text + normal! zv endfunction " Function: #toggle {{{1 function! sy#fold#toggle(do_tab) abort - if exists('w:sy_fdm') + if exists('w:sy_folded') call sy#fold#disable() - unlet w:sy_fdm + if w:sy_folded.method == 'manual' + loadview + endif + unlet w:sy_folded else - let w:sy_fdm = &foldmethod + let w:sy_folded = { 'method': &foldmethod, 'text': &foldtext } + if &foldmethod == 'manual' + let old_vop = &viewoptions + mkview + let &viewoptions = old_vop + endif call sy#fold#enable(a:do_tab) endif