vimwiki

Personal wiki for vim
git clone https://github.com/vimwiki/vimwiki.git
Log | Files | Refs | README | LICENSE

commit 0d3f526a884d4f24915f2b78fb655a3237898620
parent d265df42f59973512d457a1d3c2d9906f5206661
Author: Ivan Tishchenko <ivan.tishchenko@dsr-company.com>
Date:   Fri, 27 Nov 2015 03:13:25 +0300

Preserve fold open/close status of the TOC on save.

Since TOC is completely recreated, Vim loses its fold open/close status.
If your TOC was open, after you save it gets closed.

Fix will save fold status, and restore it after TOC is updated.

Diffstat:
Mautoload/vimwiki/base.vim | 9+++++++++
1 file changed, 9 insertions(+), 0 deletions(-)

diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim @@ -1147,9 +1147,12 @@ function! vimwiki#base#update_listing_in_buffer(strings, start_header, let cursor_line = old_cursor_pos[1] let is_cursor_after_listing = 0 + let is_fold_closed = 1 + let lines_diff = 0 if already_there + let is_fold_closed = ( foldclosed(start_lnum) > 1 ) " delete the old listing let whitespaces_in_first_line = matchstr(getline(start_lnum), '\m^\s*') let end_lnum = start_lnum + 1 @@ -1189,6 +1192,12 @@ function! vimwiki#base#update_listing_in_buffer(strings, start_header, let lines_diff += 1 endif + " Open fold, if needed + if !is_fold_closed + exe start_lnum + norm zo + endif + if is_cursor_after_listing let old_cursor_pos[1] += lines_diff endif