Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitece0850

Browse files
fix(session): respect sessionoptions=terminal#19497
fixes#13078Co-authored-by: Yuta Katayama <8683947+yutkat@users.noreply.github.com>
1 parentbcb4186 commitece0850

File tree

4 files changed

+94
-21
lines changed

4 files changed

+94
-21
lines changed

‎runtime/doc/options.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5112,7 +5112,7 @@ A jump table for the options with a short description can be found at |Q_op|.
51125112

51135113
*'sessionoptions'**'ssop'*
51145114
'sessionoptions''ssop'string(default: "blank,buffers,curdir,folds,
5115-
help,tabpages,winsize")
5115+
help,tabpages,winsize,terminal")
51165116
global
51175117
Changes the effect of the|:mksession| command. It is a comma-
51185118
separated list of words. Each word enables saving and restoring

‎src/nvim/ex_session.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ static int ses_do_win(win_T *wp)
193193
if (bt_help(wp->w_buffer)) {
194194
returnssop_flags&SSOP_HELP;
195195
}
196+
if (bt_terminal(wp->w_buffer)) {
197+
returnssop_flags&SSOP_TERMINAL;
198+
}
196199
return true;
197200
}
198201

@@ -407,6 +410,8 @@ static int put_view(FILE *fd, win_T *wp, int add_edit, unsigned *flagp, int curr
407410
if ((flagp==&ssop_flags)&&alt!=NULL&&alt->b_fname!=NULL
408411
&&*alt->b_fname!=NUL
409412
&&alt->b_p_bl
413+
// do not set balt if buffer is terminal and "terminal" is not set in options
414+
&& !(bt_terminal(alt)&& !(ssop_flags&SSOP_TERMINAL))
410415
&& (fputs("balt ",fd)<0
411416
||ses_fname(fd,alt,flagp, true)==FAIL)) {
412417
returnFAIL;
@@ -616,6 +621,7 @@ static int makeopens(FILE *fd, char_u *dirnow)
616621
FOR_ALL_BUFFERS(buf) {
617622
if (!(only_save_windows&&buf->b_nwindows==0)
618623
&& !(buf->b_help&& !(ssop_flags&SSOP_HELP))
624+
&& !(bt_terminal(buf)&& !(ssop_flags&SSOP_TERMINAL))
619625
&&buf->b_fname!=NULL
620626
&&buf->b_p_bl) {
621627
if (fprintf(fd,"badd +%"PRId64" ",

‎src/nvim/options.lua‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2063,7 +2063,7 @@ return {
20632063
type='string',list='onecomma',scope={'global'},
20642064
deny_duplicates=true,
20652065
varname='p_ssop',
2066-
defaults={if_true="blank,buffers,curdir,folds,help,tabpages,winsize"}
2066+
defaults={if_true="blank,buffers,curdir,folds,help,tabpages,winsize,terminal"}
20672067
},
20682068
{
20692069
full_name='shada',abbreviation='sd',

‎test/functional/ex_cmds/mksession_spec.lua‎

Lines changed: 86 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,85 @@ describe(':mksession', function()
4141
command('split')
4242
command('terminal')
4343
command('split')
44-
command('mksession'..session_file)
44+
command('mksession'..session_file)
4545
command('%bwipeout!')
4646

4747
-- Create a new test instance of Nvim.
4848
clear()
4949
-- Restore session.
50-
command('source'..session_file)
50+
command('source'..session_file)
5151

5252
eq(funcs.winbufnr(1),funcs.winbufnr(2))
5353
neq(funcs.winbufnr(1),funcs.winbufnr(3))
5454
end)
5555

56+
-- common testing procedure for testing "sessionoptions-=terminal"
57+
localfunctiontest_terminal_session_disabled(expected_buf_count)
58+
command('set sessionoptions-=terminal')
59+
60+
command('mksession'..session_file)
61+
62+
-- Create a new test instance of Nvim.
63+
clear()
64+
65+
-- Restore session.
66+
command('source'..session_file)
67+
68+
eq(expected_buf_count,#meths.list_bufs())
69+
end
70+
71+
it(
72+
'do not restore :terminal if not set in sessionoptions, terminal in current window #13078',
73+
function()
74+
localtmpfile_base=file_prefix..'-tmpfile'
75+
command('edit'..tmpfile_base)
76+
command('terminal')
77+
78+
localbuf_count=#meths.list_bufs()
79+
eq(2,buf_count)
80+
81+
eq('terminal',meths.buf_get_option(0,'buftype'))
82+
83+
test_terminal_session_disabled(2)
84+
85+
-- no terminal should be set. As a side effect we end up with a blank buffer
86+
eq('',meths.buf_get_option(meths.list_bufs()[1],'buftype'))
87+
eq('',meths.buf_get_option(meths.list_bufs()[2],'buftype'))
88+
end
89+
)
90+
91+
it('do not restore :terminal if not set in sessionoptions, terminal hidden #13078',function()
92+
command('terminal')
93+
localterminal_bufnr=meths.get_current_buf()
94+
95+
localtmpfile_base=file_prefix..'-tmpfile'
96+
-- make terminal hidden by opening a new file
97+
command('edit'..tmpfile_base..'1')
98+
99+
localbuf_count=#meths.list_bufs()
100+
eq(2,buf_count)
101+
102+
eq(1,funcs.getbufinfo(terminal_bufnr)[1].hidden)
103+
104+
test_terminal_session_disabled(1)
105+
106+
-- no terminal should exist here
107+
neq('',meths.buf_get_name(meths.list_bufs()[1]))
108+
end)
109+
110+
it('do not restore :terminal if not set in sessionoptions, only buffer #13078',function()
111+
command('terminal')
112+
eq('terminal',meths.buf_get_option(0,'buftype'))
113+
114+
localbuf_count=#meths.list_bufs()
115+
eq(1,buf_count)
116+
117+
test_terminal_session_disabled(1)
118+
119+
-- no terminal should be set
120+
eq('',meths.buf_get_option(0,'buftype'))
121+
end)
122+
56123
it('restores tab-local working directories',function()
57124
localtmpfile_base=file_prefix..'-tmpfile'
58125
localcwd_dir=funcs.getcwd()
@@ -102,27 +169,27 @@ describe(':mksession', function()
102169

103170
it('restores CWD for :terminal buffers #11288',function()
104171
localcwd_dir=funcs.fnamemodify('.',':p:~'):gsub([[[\/]*$]],'')
105-
cwd_dir=cwd_dir:gsub([[\]],'/')-- :mksession always uses unix slashes.
106-
localsession_path=cwd_dir..'/'..session_file
172+
cwd_dir=cwd_dir:gsub([[\]],'/')-- :mksession always uses unix slashes.
173+
localsession_path=cwd_dir..'/'..session_file
107174

108-
command('cd'..tab_dir)
175+
command('cd'..tab_dir)
109176
command('terminal')
110-
command('cd'..cwd_dir)
111-
command('mksession'..session_path)
177+
command('cd'..cwd_dir)
178+
command('mksession'..session_path)
112179
command('%bwipeout!')
113180
ifiswin()then
114-
sleep(100)-- Make sure all child processes have exited.
181+
sleep(100)-- Make sure all child processes have exited.
115182
end
116183

117184
-- Create a new test instance of Nvim.
118185
clear()
119-
command('silent source'..session_path)
186+
command('silent source'..session_path)
120187

121-
localexpected_cwd=cwd_dir..'/'..tab_dir
122-
matches('^term://'..pesc(expected_cwd)..'//%d+:',funcs.expand('%'))
188+
localexpected_cwd=cwd_dir..'/'..tab_dir
189+
matches('^term://'..pesc(expected_cwd)..'//%d+:',funcs.expand('%'))
123190
command('%bwipeout!')
124191
ifiswin()then
125-
sleep(100)-- Make sure all child processes have exited.
192+
sleep(100)-- Make sure all child processes have exited.
126193
end
127194
end)
128195

@@ -134,10 +201,10 @@ describe(':mksession', function()
134201

135202
localscreen
136203
localcwd_dir=funcs.fnamemodify('.',':p:~'):gsub([[[\/]*$]],'')
137-
localsession_path=cwd_dir..'/'..session_file
204+
localsession_path=cwd_dir..'/'..session_file
138205

139206
screen=Screen.new(50,6)
140-
screen:attach({rgb=false})
207+
screen:attach({rgb=false})
141208
localexpected_screen=[[
142209
^/ |
143210
|
@@ -153,15 +220,15 @@ describe(':mksession', function()
153220
-- Verify that the terminal's working directory is "/".
154221
screen:expect(expected_screen)
155222

156-
command('cd'..cwd_dir)
157-
command('mksession'..session_path)
223+
command('cd'..cwd_dir)
224+
command('mksession'..session_path)
158225
command('%bwipeout!')
159226

160227
-- Create a new test instance of Nvim.
161228
clear()
162229
screen=Screen.new(50,6)
163-
screen:attach({rgb=false})
164-
command('silent source'..session_path)
230+
screen:attach({rgb=false})
231+
command('silent source'..session_path)
165232

166233
-- Verify that the terminal's working directory is "/".
167234
screen:expect(expected_screen)
@@ -179,7 +246,7 @@ describe(':mksession', function()
179246
height=3,
180247
row=0,
181248
col=1,
182-
style='minimal'
249+
style='minimal',
183250
}
184251
meths.open_win(buf,false,config)
185252
localcmdheight=meths.get_option('cmdheight')

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp