vim-patch:8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright' (#14398)

Problem:    :mksession uses current value of 'splitbelow' and 'splitright'
            even though "options" is not in 'sessionoptions'. (Maxim Kim)
Solution:   Save and restore the values, instead of setting to the current
            value. (closes vim/vim#8119)
0995c81f2f

Patch v8.2.1682 is not ported.
Replace "goto fail;" with "return FAIL;".
This commit is contained in:
Jan Edmund Lazo
2021-04-22 08:14:42 -04:00
committed by GitHub
parent 8402865cba
commit bb33727922
2 changed files with 53 additions and 31 deletions

View File

@@ -690,18 +690,16 @@ static int makeopens(FILE *fd, char_u *dirnow)
return FAIL; return FAIL;
} }
// if (tab_topframe->fr_layout != FR_LEAF) {
// Save current window layout. // Save current window layout.
// PUTLINE_FAIL("let s:save_splitbelow = &splitbelow");
PUTLINE_FAIL("set splitbelow splitright"); PUTLINE_FAIL("let s:save_splitright = &splitright");
if (ses_win_rec(fd, tab_topframe) == FAIL) { PUTLINE_FAIL("set splitbelow splitright");
return FAIL; if (ses_win_rec(fd, tab_topframe) == FAIL) {
} return FAIL;
if (!p_sb && put_line(fd, "set nosplitbelow") == FAIL) { }
return FAIL; PUTLINE_FAIL("let &splitbelow = s:save_splitbelow");
} PUTLINE_FAIL("let &splitright = s:save_splitright");
if (!p_spr && put_line(fd, "set nosplitright") == FAIL) {
return FAIL;
} }
// //
@@ -720,22 +718,26 @@ static int makeopens(FILE *fd, char_u *dirnow)
} }
} }
// Go to the first window. if (tab_firstwin->w_next != NULL) {
PUTLINE_FAIL("wincmd t"); // Go to the first window.
PUTLINE_FAIL("wincmd t");
// If more than one window, see if sizes can be restored. // If more than one window, see if sizes can be restored.
// First set 'winheight' and 'winwidth' to 1 to avoid the windows being // First set 'winheight' and 'winwidth' to 1 to avoid the windows
// resized when moving between windows. // being resized when moving between windows.
// Do this before restoring the view, so that the topline and the // Do this before restoring the view, so that the topline and the
// cursor can be set. This is done again below. // cursor can be set. This is done again below.
// winminheight and winminwidth need to be set to avoid an error if the // winminheight and winminwidth need to be set to avoid an error if
// user has set winheight or winwidth. // the user has set winheight or winwidth.
if (fprintf(fd, PUTLINE_FAIL("let s:save_winminheight = &winminheight");
"set winminheight=0\n" PUTLINE_FAIL("let s:save_winminwidth = &winminwidth");
"set winheight=1\n" if (fprintf(fd,
"set winminwidth=0\n" "set winminheight=0\n"
"set winwidth=1\n") < 0) { "set winheight=1\n"
return FAIL; "set winminwidth=0\n"
"set winwidth=1\n") < 0) {
return FAIL;
}
} }
if (nr > 1 && ses_winsizes(fd, restore_size, tab_firstwin) == FAIL) { if (nr > 1 && ses_winsizes(fd, restore_size, tab_firstwin) == FAIL) {
return FAIL; return FAIL;
@@ -817,18 +819,20 @@ static int makeopens(FILE *fd, char_u *dirnow)
return FAIL; return FAIL;
} }
// Re-apply options. // Re-apply 'winheight', 'winwidth' and 'shortmess'.
if (fprintf(fd, if (fprintf(fd,
"set winheight=%" PRId64 " winwidth=%" PRId64 "set winheight=%" PRId64 " winwidth=%" PRId64
" winminheight=%" PRId64 " winminwidth=%" PRId64
" shortmess=%s\n", " shortmess=%s\n",
(int64_t)p_wh, (int64_t)p_wh,
(int64_t)p_wiw, (int64_t)p_wiw,
(int64_t)p_wmh,
(int64_t)p_wmw,
p_shm) < 0) { p_shm) < 0) {
return FAIL; return FAIL;
} }
if (tab_firstwin->w_next != NULL) {
// Restore 'winminheight' and 'winminwidth'.
PUTLINE_FAIL("let &winminheight = s:save_winminheight");
PUTLINE_FAIL("let &winminwidth = s:save_winminwidth");
}
// //
// Lastly, execute the x.vim file if it exists. // Lastly, execute the x.vim file if it exists.

View File

@@ -680,6 +680,24 @@ func Test_mksession_winpos()
set sessionoptions& set sessionoptions&
endfunc endfunc
" Test for mksession without options restores winminheight
func Test_mksession_winminheight()
set sessionoptions-=options
split
mksession! Xtest_mks.out
let found_restore = 0
let lines = readfile('Xtest_mks.out')
for line in lines
if line =~ '= s:save_winmin\(width\|height\)'
let found_restore += 1
endif
endfor
call assert_equal(2, found_restore)
call delete('Xtest_mks.out')
close
set sessionoptions&
endfunc
" Test for mksession with 'compatible' option " Test for mksession with 'compatible' option
func Test_mksession_compatible() func Test_mksession_compatible()
throw 'skipped: Nvim does not support "compatible" option' throw 'skipped: Nvim does not support "compatible" option'