aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustavo Sampaio <gbritosampaio@gmail.com>2022-08-01 09:13:46 -0300
committerGitHub <noreply@github.com>2022-08-01 05:13:46 -0700
commitece0850b7393114cac651cf9f43fc2c5e1b1cf50 (patch)
treeca4a17a3ea56d9696b41f85c6af53da82650dac1
parentbcb4186cf67b22dab238248a809f6c3f09a5424d (diff)
downloadrneovim-ece0850b7393114cac651cf9f43fc2c5e1b1cf50.tar.gz
rneovim-ece0850b7393114cac651cf9f43fc2c5e1b1cf50.tar.bz2
rneovim-ece0850b7393114cac651cf9f43fc2c5e1b1cf50.zip
fix(session): respect sessionoptions=terminal #19497
fixes #13078 Co-authored-by: Yuta Katayama <8683947+yutkat@users.noreply.github.com>
-rw-r--r--runtime/doc/options.txt2
-rw-r--r--src/nvim/ex_session.c6
-rw-r--r--src/nvim/options.lua2
-rw-r--r--test/functional/ex_cmds/mksession_spec.lua105
4 files changed, 94 insertions, 21 deletions
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index 04ba9539c5..ffeed6f977 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -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
diff --git a/src/nvim/ex_session.c b/src/nvim/ex_session.c
index 6ca6da9cd0..1d670afa6d 100644
--- a/src/nvim/ex_session.c
+++ b/src/nvim/ex_session.c
@@ -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 " ",
diff --git a/src/nvim/options.lua b/src/nvim/options.lua
index 9e4a6a084c..2f941f5d0c 100644
--- a/src/nvim/options.lua
+++ b/src/nvim/options.lua
@@ -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',
diff --git a/test/functional/ex_cmds/mksession_spec.lua b/test/functional/ex_cmds/mksession_spec.lua
index 405813c12b..ee8da2932d 100644
--- a/test/functional/ex_cmds/mksession_spec.lua
+++ b/test/functional/ex_cmds/mksession_spec.lua
@@ -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')