patch 9.1.1317: noisy error when restoring folds from session fails

Commit: 
https://github.com/vim/vim/commit/cca5dea76e5bfa8369ae9d54b35fd140bb9159b4
Author: Igor Lacerda <igor...@ufmg.br>
Date:   Thu Apr 17 20:41:31 2025 +0200

    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: #15813
    closes: #17127
    
    Signed-off-by: Igor Lacerda <igor...@ufmg.br>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/fold.c b/src/fold.c
index b165dc9b0..4824a807c 100644
--- a/src/fold.c
+++ b/src/fold.c
@@ -3576,7 +3576,7 @@ put_folds_recurse(FILE *fd, garray_T *gap, linenr_T off)
        // Do nested folds first, they will be created closed.
        if (put_folds_recurse(fd, &fp->fd_nested, off + fp->fd_top) == FAIL)
            return FAIL;
-       if (fprintf(fd, "%ld,%ldfold", fp->fd_top + off,
+       if (fprintf(fd, "sil! %ld,%ldfold", fp->fd_top + off,
                                        fp->fd_top + off + fp->fd_len - 1) < 0
                || put_eol(fd) == FAIL)
            return FAIL;
@@ -3609,9 +3609,10 @@ put_foldopen_recurse(
            if (fp->fd_nested.ga_len > 0)
            {
                // open nested folds while this fold is open
+               // ignore errors
                if (fprintf(fd, "%ld", 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,
                                                             off + fp->fd_top)
@@ -3652,7 +3653,7 @@ put_fold_open_close(FILE *fd, fold_T *fp, linenr_T off)
 {
     if (fprintf(fd, "%ld", 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/src/testdir/test_mksession.vim b/src/testdir/test_mksession.vim
index d0ee6e8a7..72a9376c3 100644
--- a/src/testdir/test_mksession.vim
+++ b/src/testdir/test_mksession.vim
@@ -1264,6 +1264,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()
   if has('win32')
diff --git a/src/version.c b/src/version.c
index abd0fa366..e6c8690d2 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1317,
 /**/
     1316,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/vim_dev/E1u5UES-008z1D-DV%40256bit.org.

Raspunde prin e-mail lui