mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
fix(session): respect sessionoptions=terminal #19497
fixes #13078 Co-authored-by: Yuta Katayama <8683947+yutkat@users.noreply.github.com>
This commit is contained in:
parent
bcb4186cf6
commit
ece0850b73
@ -5112,7 +5112,7 @@ A jump table for the options with a short description can be found at |Q_op|.
|
||||
|
||||
*'sessionoptions'* *'ssop'*
|
||||
'sessionoptions' 'ssop' string (default: "blank,buffers,curdir,folds,
|
||||
help,tabpages,winsize")
|
||||
help,tabpages,winsize,terminal")
|
||||
global
|
||||
Changes the effect of the |:mksession| command. It is a comma-
|
||||
separated list of words. Each word enables saving and restoring
|
||||
|
@ -193,6 +193,9 @@ static int ses_do_win(win_T *wp)
|
||||
if (bt_help(wp->w_buffer)) {
|
||||
return ssop_flags & SSOP_HELP;
|
||||
}
|
||||
if (bt_terminal(wp->w_buffer)) {
|
||||
return ssop_flags & SSOP_TERMINAL;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -407,6 +410,8 @@ static int put_view(FILE *fd, win_T *wp, int add_edit, unsigned *flagp, int curr
|
||||
if ((flagp == &ssop_flags) && alt != NULL && alt->b_fname != NULL
|
||||
&& *alt->b_fname != NUL
|
||||
&& alt->b_p_bl
|
||||
// do not set balt if buffer is terminal and "terminal" is not set in options
|
||||
&& !(bt_terminal(alt) && !(ssop_flags & SSOP_TERMINAL))
|
||||
&& (fputs("balt ", fd) < 0
|
||||
|| ses_fname(fd, alt, flagp, true) == FAIL)) {
|
||||
return FAIL;
|
||||
@ -616,6 +621,7 @@ static int makeopens(FILE *fd, char_u *dirnow)
|
||||
FOR_ALL_BUFFERS(buf) {
|
||||
if (!(only_save_windows && buf->b_nwindows == 0)
|
||||
&& !(buf->b_help && !(ssop_flags & SSOP_HELP))
|
||||
&& !(bt_terminal(buf) && !(ssop_flags & SSOP_TERMINAL))
|
||||
&& buf->b_fname != NULL
|
||||
&& buf->b_p_bl) {
|
||||
if (fprintf(fd, "badd +%" PRId64 " ",
|
||||
|
@ -2063,7 +2063,7 @@ return {
|
||||
type='string', list='onecomma', scope={'global'},
|
||||
deny_duplicates=true,
|
||||
varname='p_ssop',
|
||||
defaults={if_true="blank,buffers,curdir,folds,help,tabpages,winsize"}
|
||||
defaults={if_true="blank,buffers,curdir,folds,help,tabpages,winsize,terminal"}
|
||||
},
|
||||
{
|
||||
full_name='shada', abbreviation='sd',
|
||||
|
@ -41,18 +41,85 @@ describe(':mksession', function()
|
||||
command('split')
|
||||
command('terminal')
|
||||
command('split')
|
||||
command('mksession '..session_file)
|
||||
command('mksession ' .. session_file)
|
||||
command('%bwipeout!')
|
||||
|
||||
-- Create a new test instance of Nvim.
|
||||
clear()
|
||||
-- Restore session.
|
||||
command('source '..session_file)
|
||||
command('source ' .. session_file)
|
||||
|
||||
eq(funcs.winbufnr(1), funcs.winbufnr(2))
|
||||
neq(funcs.winbufnr(1), funcs.winbufnr(3))
|
||||
end)
|
||||
|
||||
-- common testing procedure for testing "sessionoptions-=terminal"
|
||||
local function test_terminal_session_disabled(expected_buf_count)
|
||||
command('set sessionoptions-=terminal')
|
||||
|
||||
command('mksession ' .. session_file)
|
||||
|
||||
-- Create a new test instance of Nvim.
|
||||
clear()
|
||||
|
||||
-- Restore session.
|
||||
command('source ' .. session_file)
|
||||
|
||||
eq(expected_buf_count, #meths.list_bufs())
|
||||
end
|
||||
|
||||
it(
|
||||
'do not restore :terminal if not set in sessionoptions, terminal in current window #13078',
|
||||
function()
|
||||
local tmpfile_base = file_prefix .. '-tmpfile'
|
||||
command('edit ' .. tmpfile_base)
|
||||
command('terminal')
|
||||
|
||||
local buf_count = #meths.list_bufs()
|
||||
eq(2, buf_count)
|
||||
|
||||
eq('terminal', meths.buf_get_option(0, 'buftype'))
|
||||
|
||||
test_terminal_session_disabled(2)
|
||||
|
||||
-- no terminal should be set. As a side effect we end up with a blank buffer
|
||||
eq('', meths.buf_get_option(meths.list_bufs()[1], 'buftype'))
|
||||
eq('', meths.buf_get_option(meths.list_bufs()[2], 'buftype'))
|
||||
end
|
||||
)
|
||||
|
||||
it('do not restore :terminal if not set in sessionoptions, terminal hidden #13078', function()
|
||||
command('terminal')
|
||||
local terminal_bufnr = meths.get_current_buf()
|
||||
|
||||
local tmpfile_base = file_prefix .. '-tmpfile'
|
||||
-- make terminal hidden by opening a new file
|
||||
command('edit ' .. tmpfile_base .. '1')
|
||||
|
||||
local buf_count = #meths.list_bufs()
|
||||
eq(2, buf_count)
|
||||
|
||||
eq(1, funcs.getbufinfo(terminal_bufnr)[1].hidden)
|
||||
|
||||
test_terminal_session_disabled(1)
|
||||
|
||||
-- no terminal should exist here
|
||||
neq('', meths.buf_get_name(meths.list_bufs()[1]))
|
||||
end)
|
||||
|
||||
it('do not restore :terminal if not set in sessionoptions, only buffer #13078', function()
|
||||
command('terminal')
|
||||
eq('terminal', meths.buf_get_option(0, 'buftype'))
|
||||
|
||||
local buf_count = #meths.list_bufs()
|
||||
eq(1, buf_count)
|
||||
|
||||
test_terminal_session_disabled(1)
|
||||
|
||||
-- no terminal should be set
|
||||
eq('', meths.buf_get_option(0, 'buftype'))
|
||||
end)
|
||||
|
||||
it('restores tab-local working directories', function()
|
||||
local tmpfile_base = file_prefix .. '-tmpfile'
|
||||
local cwd_dir = funcs.getcwd()
|
||||
@ -102,27 +169,27 @@ describe(':mksession', function()
|
||||
|
||||
it('restores CWD for :terminal buffers #11288', function()
|
||||
local cwd_dir = funcs.fnamemodify('.', ':p:~'):gsub([[[\/]*$]], '')
|
||||
cwd_dir = cwd_dir:gsub([[\]], '/') -- :mksession always uses unix slashes.
|
||||
local session_path = cwd_dir..'/'..session_file
|
||||
cwd_dir = cwd_dir:gsub([[\]], '/') -- :mksession always uses unix slashes.
|
||||
local session_path = cwd_dir .. '/' .. session_file
|
||||
|
||||
command('cd '..tab_dir)
|
||||
command('cd ' .. tab_dir)
|
||||
command('terminal')
|
||||
command('cd '..cwd_dir)
|
||||
command('mksession '..session_path)
|
||||
command('cd ' .. cwd_dir)
|
||||
command('mksession ' .. session_path)
|
||||
command('%bwipeout!')
|
||||
if iswin() then
|
||||
sleep(100) -- Make sure all child processes have exited.
|
||||
sleep(100) -- Make sure all child processes have exited.
|
||||
end
|
||||
|
||||
-- Create a new test instance of Nvim.
|
||||
clear()
|
||||
command('silent source '..session_path)
|
||||
command('silent source ' .. session_path)
|
||||
|
||||
local expected_cwd = cwd_dir..'/'..tab_dir
|
||||
matches('^term://'..pesc(expected_cwd)..'//%d+:', funcs.expand('%'))
|
||||
local expected_cwd = cwd_dir .. '/' .. tab_dir
|
||||
matches('^term://' .. pesc(expected_cwd) .. '//%d+:', funcs.expand('%'))
|
||||
command('%bwipeout!')
|
||||
if iswin() then
|
||||
sleep(100) -- Make sure all child processes have exited.
|
||||
sleep(100) -- Make sure all child processes have exited.
|
||||
end
|
||||
end)
|
||||
|
||||
@ -134,10 +201,10 @@ describe(':mksession', function()
|
||||
|
||||
local screen
|
||||
local cwd_dir = funcs.fnamemodify('.', ':p:~'):gsub([[[\/]*$]], '')
|
||||
local session_path = cwd_dir..'/'..session_file
|
||||
local session_path = cwd_dir .. '/' .. session_file
|
||||
|
||||
screen = Screen.new(50, 6)
|
||||
screen:attach({rgb=false})
|
||||
screen:attach({ rgb = false })
|
||||
local expected_screen = [[
|
||||
^/ |
|
||||
|
|
||||
@ -153,15 +220,15 @@ describe(':mksession', function()
|
||||
-- Verify that the terminal's working directory is "/".
|
||||
screen:expect(expected_screen)
|
||||
|
||||
command('cd '..cwd_dir)
|
||||
command('mksession '..session_path)
|
||||
command('cd ' .. cwd_dir)
|
||||
command('mksession ' .. session_path)
|
||||
command('%bwipeout!')
|
||||
|
||||
-- Create a new test instance of Nvim.
|
||||
clear()
|
||||
screen = Screen.new(50, 6)
|
||||
screen:attach({rgb=false})
|
||||
command('silent source '..session_path)
|
||||
screen:attach({ rgb = false })
|
||||
command('silent source ' .. session_path)
|
||||
|
||||
-- Verify that the terminal's working directory is "/".
|
||||
screen:expect(expected_screen)
|
||||
@ -179,7 +246,7 @@ describe(':mksession', function()
|
||||
height = 3,
|
||||
row = 0,
|
||||
col = 1,
|
||||
style = 'minimal'
|
||||
style = 'minimal',
|
||||
}
|
||||
meths.open_win(buf, false, config)
|
||||
local cmdheight = meths.get_option('cmdheight')
|
||||
|
Loading…
Reference in New Issue
Block a user