From cf67f19ac2104ece76d040c8184bc287428299b3 Mon Sep 17 00:00:00 2001 From: Alexandre Dubray Date: Tue, 9 Jan 2018 12:01:02 +0100 Subject: mksession: restore same :term buf in split windows Problem: When session-restore creates a terminal buffer with command like `:edit term://.//16450:/bin/bash`, the buffer gets a different name (depends on PID). Thus the later call to `bufexists('term://.//16450:/bin/bash)` will return false. Solution: Force the buffer name with :file. This as least ensures the same buffer will show in multiple windows correctly, as expected when saving the session. But it still has problems: 1. the PID in the buffer name is bogus 2. redundant :terminal buffers still hang around fix #5250 --- test/functional/ex_cmds/mksession_spec.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ex_cmds/mksession_spec.lua b/test/functional/ex_cmds/mksession_spec.lua index 855f8105aa..726cfe7fe5 100644 --- a/test/functional/ex_cmds/mksession_spec.lua +++ b/test/functional/ex_cmds/mksession_spec.lua @@ -91,4 +91,23 @@ 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) -- cgit From 1e103b3c12597a9dd2f20d45686822ab6ee089b0 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 26 Jan 2020 02:43:12 -0800 Subject: mksession: simplify generated commands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Doing ":file …" immediately after is enough to fixup the :terminal buffer name. ref #5250 --- test/functional/ex_cmds/mksession_spec.lua | 40 ++++++++++++++++-------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ex_cmds/mksession_spec.lua b/test/functional/ex_cmds/mksession_spec.lua index 726cfe7fe5..305850a09e 100644 --- a/test/functional/ex_cmds/mksession_spec.lua +++ b/test/functional/ex_cmds/mksession_spec.lua @@ -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) -- cgit From 1c3ca4f18fdc403813d8959b49626ac1c99e2c59 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 26 Jan 2020 14:26:01 -0800 Subject: mksession: always unix slashes "/" for filepaths --- test/functional/ex_cmds/mksession_spec.lua | 5 +++-- test/functional/helpers.lua | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ex_cmds/mksession_spec.lua b/test/functional/ex_cmds/mksession_spec.lua index 305850a09e..949724bb53 100644 --- a/test/functional/ex_cmds/mksession_spec.lua +++ b/test/functional/ex_cmds/mksession_spec.lua @@ -96,7 +96,8 @@ describe(':mksession', function() it('restores CWD for :terminal buffers #11288', function() local cwd_dir = funcs.fnamemodify('.', ':p:~'):gsub([[[\/]*$]], '') - local session_path = cwd_dir..get_pathsep()..session_file + cwd_dir = cwd_dir:gsub([[\]], '/') -- :mksession always uses unix slashes. + local session_path = cwd_dir..'/'..session_file command('cd '..tab_dir) command('terminal echo $PWD') @@ -108,7 +109,7 @@ describe(':mksession', function() clear() command('silent source '..session_path) - local expected_cwd = cwd_dir..get_pathsep()..tab_dir + local expected_cwd = cwd_dir..'/'..tab_dir matches('^term://'..pesc(expected_cwd)..'//%d+:', funcs.expand('%')) command('qall!') end) diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 3ffc6137d6..53c4d140b6 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -794,7 +794,7 @@ function module.alter_slashes(obj) end return ret else - assert(false, 'Could only alter slashes for tables of strings and strings') + assert(false, 'expected string or table of strings, got '..type(obj)) end end -- cgit