neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit e2e6c159d3dc5897bb0a51763e70c78845b97d34
parent 0eb708aa8a1af8bec8486ddceb10c2cd515b0ca0
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Fri, 18 Apr 2025 08:06:24 +0800

vim-patch:9.1.1317: noisy error when restoring folds from session fails

Problem:  noisy error when restoring folds from session fails
Solution: ignore errors silently when sourcing session file.
          (Igor Lacerda)

fixes: vim/vim#15813
closes: vim/vim#17127

https://github.com/vim/vim/commit/cca5dea76e5bfa8369ae9d54b35fd140bb9159b4

Co-authored-by: Igor Lacerda <igorlfs@ufmg.br>

Diffstat:
Msrc/nvim/fold.c | 7++++---
Mtest/old/testdir/test_mksession.vim | 18++++++++++++++++++
2 files changed, 22 insertions(+), 3 deletions(-)

diff --git 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 @@ -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'