diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 80a1ed9667..2a605303c7 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -3099,7 +3099,7 @@ static int put_folds_recurse(FILE *fd, garray_T *gap, linenr_T off) if (put_folds_recurse(fd, &fp->fd_nested, off + fp->fd_top) == FAIL) { return FAIL; } - if (fprintf(fd, "%" PRId64 ",%" PRId64 "fold", + if (fprintf(fd, "sil! %" PRId64 ",%" PRId64 "fold", (int64_t)fp->fd_top + off, (int64_t)(fp->fd_top + off + fp->fd_len - 1)) < 0 || put_eol(fd) == FAIL) { @@ -3121,9 +3121,10 @@ static int put_foldopen_recurse(FILE *fd, win_T *wp, garray_T *gap, linenr_T off if (fp->fd_flags != FD_LEVEL) { if (!GA_EMPTY(&fp->fd_nested)) { // open nested folds while this fold is open + // ignore errors if (fprintf(fd, "%" PRId64, (int64_t)fp->fd_top + off) < 0 || put_eol(fd) == FAIL - || put_line(fd, "normal! zo") == FAIL) { + || put_line(fd, "sil! normal! zo") == FAIL) { return FAIL; } if (put_foldopen_recurse(fd, wp, &fp->fd_nested, @@ -3164,7 +3165,7 @@ static int put_fold_open_close(FILE *fd, fold_T *fp, linenr_T off) { if (fprintf(fd, "%" PRIdLINENR, fp->fd_top + off) < 0 || put_eol(fd) == FAIL - || fprintf(fd, "normal! z%c", + || fprintf(fd, "sil! normal! z%c", fp->fd_flags == FD_CLOSED ? 'c' : 'o') < 0 || put_eol(fd) == FAIL) { return FAIL; diff --git a/test/old/testdir/test_mksession.vim b/test/old/testdir/test_mksession.vim index 1084204970..8c9b3f1c22 100644 --- a/test/old/testdir/test_mksession.vim +++ b/test/old/testdir/test_mksession.vim @@ -1198,6 +1198,24 @@ func Test_mkview_manual_fold() bw! endfunc +" Test for handling invalid folds within views +func Test_mkview_ignore_invalid_folds() + call writefile(range(1,10), 'Xmkvfile', 'D') + new Xmkvfile + " create some folds + 5,6fold + 4,7fold + mkview Xview + normal zE + " delete lines to make folds invalid + call deletebufline('', 6, '$') + source Xview + call assert_equal([-1, -1, -1, -1, -1, -1], [foldclosed(3), foldclosed(4), + \ foldclosed(5), foldclosed(6), foldclosed(7), foldclosed(8)]) + call delete('Xview') + bw! +endfunc + " Test default 'viewdir' value func Test_mkview_default_home() throw 'Skipped: N/A'