mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
mksession: simplify generated commands
Doing ":file …" immediately after is enough to fixup the :terminal buffer name. ref #5250
This commit is contained in:
parent
cf67f19ac2
commit
1e103b3c12
@ -8090,14 +8090,12 @@ static void close_redir(void)
|
||||
static int mksession_nl = FALSE; /* use NL only in put_eol() */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* ":mkexrc", ":mkvimrc", ":mkview" and ":mksession".
|
||||
*/
|
||||
/// ":mkexrc", ":mkvimrc", ":mkview", ":mksession".
|
||||
static void ex_mkrc(exarg_T *eap)
|
||||
{
|
||||
FILE *fd;
|
||||
int failed = false;
|
||||
int view_session = false;
|
||||
int view_session = false; // :mkview, :mksession
|
||||
int using_vdir = false; // using 'viewdir'?
|
||||
char *viewFile = NULL;
|
||||
unsigned *flagp;
|
||||
@ -8159,11 +8157,11 @@ static void ex_mkrc(exarg_T *eap)
|
||||
failed = TRUE;
|
||||
}
|
||||
|
||||
if (!view_session
|
||||
|| (eap->cmdidx == CMD_mksession
|
||||
&& (*flagp & SSOP_OPTIONS)))
|
||||
if (!view_session || (eap->cmdidx == CMD_mksession
|
||||
&& (*flagp & SSOP_OPTIONS))) {
|
||||
failed |= (makemap(fd, NULL) == FAIL
|
||||
|| makeset(fd, OPT_GLOBAL, FALSE) == FAIL);
|
||||
}
|
||||
|
||||
if (!failed && view_session) {
|
||||
if (put_line(fd,
|
||||
@ -9119,15 +9117,13 @@ char_u *expand_sfile(char_u *arg)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Write openfile commands for the current buffers to an .exrc file.
|
||||
* Return FAIL on error, OK otherwise.
|
||||
*/
|
||||
static int
|
||||
makeopens(
|
||||
FILE *fd,
|
||||
char_u *dirnow /* Current directory name */
|
||||
)
|
||||
/// Writes commands for restoring the current buffers, for :mksession.
|
||||
///
|
||||
/// @param dirnow Current directory name
|
||||
/// @param fd File descriptor to write to
|
||||
///
|
||||
/// @return FAIL on error, OK otherwise.
|
||||
static int makeopens(FILE *fd, char_u *dirnow)
|
||||
{
|
||||
int only_save_windows = TRUE;
|
||||
int nr;
|
||||
@ -9240,12 +9236,11 @@ makeopens(
|
||||
restore_stal = TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* May repeat putting Windows for each tab, when "tabpages" is in
|
||||
* 'sessionoptions'.
|
||||
* Don't use goto_tabpage(), it may change directory and trigger
|
||||
* autocommands.
|
||||
*/
|
||||
//
|
||||
// For each tab:
|
||||
// - Put windows for each tab, when "tabpages" is in 'sessionoptions'.
|
||||
// - Don't use goto_tabpage(), it may change CWD and trigger autocommands.
|
||||
//
|
||||
tab_firstwin = firstwin; /* first window in tab page "tabnr" */
|
||||
tab_topframe = topframe;
|
||||
for (tabnr = 1;; tabnr++) {
|
||||
@ -9269,11 +9264,11 @@ makeopens(
|
||||
need_tabnew = TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Before creating the window layout, try loading one file. If this
|
||||
* is aborted we don't end up with a number of useless windows.
|
||||
* This may have side effects! (e.g., compressed or network file).
|
||||
*/
|
||||
//
|
||||
// Before creating the window layout, try loading one file. If this
|
||||
// is aborted we don't end up with a number of useless windows.
|
||||
// This may have side effects! (e.g., compressed or network file).
|
||||
//
|
||||
for (wp = tab_firstwin; wp != NULL; wp = wp->w_next) {
|
||||
if (ses_do_win(wp)
|
||||
&& wp->w_buffer->b_ffname != NULL
|
||||
@ -9343,13 +9338,9 @@ makeopens(
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Restore the view of the window (options, file, cursor, etc.).
|
||||
*/
|
||||
if (put_line(fd, "let s:buffer_names = []") == FAIL) {
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
//
|
||||
// Restore the view of the window (options, file, cursor, etc.).
|
||||
//
|
||||
for (wp = tab_firstwin; wp != NULL; wp = wp->w_next) {
|
||||
if (!ses_do_win(wp))
|
||||
continue;
|
||||
@ -9361,16 +9352,6 @@ makeopens(
|
||||
next_arg_idx = wp->w_arg_idx;
|
||||
}
|
||||
|
||||
if (put_line(fd, "for [s:name, s:tbuf] in s:buffer_names") == FAIL
|
||||
|| put_line(fd, " if buflisted(s:tbuf)") == FAIL
|
||||
|| put_line(fd, " execute 'buffer' fnameescape(s:tbuf)") == FAIL
|
||||
|| put_line(fd, " execute 'file' fnameescape(s:name)") == FAIL
|
||||
|| put_line(fd, " endif") == FAIL
|
||||
|| put_line(fd, "endfor") == FAIL
|
||||
|| put_line(fd, "unlet! s:buffer_names s:tbuf s:name") == FAIL) {
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
/* The argument index in the first tab page is zero, need to set it in
|
||||
* each window. For further tab pages it's the window where we do
|
||||
* "tabedit". */
|
||||
@ -9677,14 +9658,7 @@ put_view(
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
if (fputs("call add(s:buffer_names, [bufname('%'),'", fd) < 0
|
||||
|| ses_fname(fd, wp->w_buffer, flagp, false) == FAIL
|
||||
|| fputs("'])", fd) < 0
|
||||
|| put_eol(fd) == FAIL) {
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
if (fputs("file ", fd) < 0
|
||||
if (fputs("silent file ", fd) < 0
|
||||
|| ses_fname(fd, wp->w_buffer, flagp, false) == FAIL
|
||||
|| put_eol(fd) == FAIL) {
|
||||
return FAIL;
|
||||
|
@ -26,6 +26,27 @@ describe(':mksession', function()
|
||||
rmdir(tab_dir)
|
||||
end)
|
||||
|
||||
it('restores same :terminal buf in splits', function()
|
||||
-- If the same :terminal is displayed in multiple windows, :mksession
|
||||
-- should restore it as such.
|
||||
|
||||
-- Create two windows showing the same :terminal buffer.
|
||||
command('terminal')
|
||||
command('split')
|
||||
command('terminal')
|
||||
command('split')
|
||||
command('mksession '..session_file)
|
||||
|
||||
-- Create a new test instance of Nvim.
|
||||
command('qall!')
|
||||
clear()
|
||||
-- Restore session.
|
||||
command('source '..session_file)
|
||||
|
||||
eq({3,3,2},
|
||||
{funcs.winbufnr(1), funcs.winbufnr(2), funcs.winbufnr(3)})
|
||||
end)
|
||||
|
||||
it('restores tab-local working directories', function()
|
||||
local tmpfile_base = file_prefix .. '-tmpfile'
|
||||
local cwd_dir = funcs.getcwd()
|
||||
@ -91,23 +112,4 @@ describe(':mksession', function()
|
||||
matches('^term://'..pesc(expected_cwd)..'//%d+:', funcs.expand('%'))
|
||||
command('qall!')
|
||||
end)
|
||||
|
||||
it('restores multiple windows with same terminal instances', function()
|
||||
-- Create a view with two buffers referencing the same terminal instance
|
||||
command('terminal')
|
||||
command('split')
|
||||
command('mksession ' .. session_file)
|
||||
|
||||
clear()
|
||||
|
||||
command('source ' .. session_file)
|
||||
-- Getting the name of the buffer shown to compare with the other window
|
||||
local eval = helpers.eval
|
||||
|
||||
command('exe 1 . "wincmd w"')
|
||||
local expected_pid = eval('b:terminal_job_pid')
|
||||
|
||||
command('exe 2 . "wincmd w"')
|
||||
eq(expected_pid, eval('b:terminal_job_pid'))
|
||||
end)
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user