From 99a1a58c66b9bc56d98ee7a8d249d594669e9573 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 11 Mar 2017 22:46:20 +0100 Subject: DirChanged: Publish _after_ updating win/tab CWD. So getcwd() works correctly during DirChanged event. Closes #6260 --- test/functional/autocmd/dirchanged_spec.lua | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'test/functional') diff --git a/test/functional/autocmd/dirchanged_spec.lua b/test/functional/autocmd/dirchanged_spec.lua index 15196dbd44..f51a978221 100644 --- a/test/functional/autocmd/dirchanged_spec.lua +++ b/test/functional/autocmd/dirchanged_spec.lua @@ -20,7 +20,9 @@ describe('autocmd DirChanged', function() before_each(function() clear() - command('autocmd DirChanged * let [g:event, g:scope, g:cdcount] = [copy(v:event), expand(""), 1 + get(g:, "cdcount", 0)]') + command('autocmd DirChanged * let [g:getcwd_rv, g:event, g:amatch, g:cdcount] ' + ..' = [getcwd(), copy(v:event), expand(""), 1 + get(g:, "cdcount", 0)]' + ..[[ | let g:event['cwd'] = substitute(g:event['cwd'], '\\', '/', 'g') ]]) end) it('sets v:event', function() @@ -37,6 +39,17 @@ describe('autocmd DirChanged', function() eq(3, eval('g:cdcount')) end) + it('sets getcwd() during event #6260', function() + command('lcd '..dirs[1]) + eq(dirs[1], eval('g:getcwd_rv')) + + command('tcd '..dirs[2]) + eq(dirs[2], eval('g:getcwd_rv')) + + command('cd '..dirs[3]) + eq(dirs[3], eval('g:getcwd_rv')) + end) + it('disallows recursion', function() command('set shellslash') -- Set up a _nested_ handler. @@ -50,13 +63,13 @@ describe('autocmd DirChanged', function() it('sets to CWD "scope"', function() command('lcd '..dirs[1]) - eq('window', eval('g:scope')) + eq('window', eval('g:amatch')) command('tcd '..dirs[2]) - eq('tab', eval('g:scope')) + eq('tab', eval('g:amatch')) command('cd '..dirs[3]) - eq('global', eval('g:scope')) + eq('global', eval('g:amatch')) end) it('does not trigger if :cd fails', function() -- cgit From d9fcbc2cfb5f20f63a2870624ce48a58cf918ea8 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 12 Mar 2017 12:11:10 +0100 Subject: DirChanged: trigger when switching scopes Closes #6054 --- test/functional/autocmd/dirchanged_spec.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test/functional') diff --git a/test/functional/autocmd/dirchanged_spec.lua b/test/functional/autocmd/dirchanged_spec.lua index f51a978221..7a1f79fd34 100644 --- a/test/functional/autocmd/dirchanged_spec.lua +++ b/test/functional/autocmd/dirchanged_spec.lua @@ -109,6 +109,34 @@ describe('autocmd DirChanged', function() eq({cwd=dirs[2], scope='window'}, eval('g:event')) end) + it("is triggered by switching to win/tab with different CWD #6054", function() + command('lcd '..dirs[3]) -- window 3 + command('split '..dirs[2]..'/foo') -- window 2 + command('lcd '..dirs[2]) + command('split '..dirs[1]..'/bar') -- window 1 + command('lcd '..dirs[1]) + + command('2wincmd w') -- window 2 + eq({cwd=dirs[2], scope='window'}, eval('g:event')) + + eq(4, eval('g:cdcount')) + command('tabnew') -- tab 2 (tab-local CWD) + eq(4, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tcd '..dirs[3]) + command('tabnext') -- tab 1 (no tab-local CWD) + eq({cwd=dirs[2], scope='window'}, eval('g:event')) + command('tabnext') -- tab 2 + eq({cwd=dirs[3], scope='tab'}, eval('g:event')) + eq(7, eval('g:cdcount')) + + command('tabnext') -- tab 1 + command('3wincmd w') -- window 3 + eq(9, eval('g:cdcount')) + command('tabnext') -- tab 2 (has the *same* CWD) + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + + end) + it('is triggered by nvim_set_current_dir()', function() request('nvim_set_current_dir', dirs[1]) eq({cwd=dirs[1], scope='global'}, eval('g:event')) -- cgit From c5e61b41a53c4fac93f1101ece1a23168eccb3a3 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 12 Mar 2017 12:12:26 +0100 Subject: DirChanged: avoid redundant events on 'autochdir' --- test/functional/autocmd/dirchanged_spec.lua | 49 +++++++++++++++-------------- 1 file changed, 26 insertions(+), 23 deletions(-) (limited to 'test/functional') diff --git a/test/functional/autocmd/dirchanged_spec.lua b/test/functional/autocmd/dirchanged_spec.lua index 7a1f79fd34..63cf0bc410 100644 --- a/test/functional/autocmd/dirchanged_spec.lua +++ b/test/functional/autocmd/dirchanged_spec.lua @@ -20,34 +20,36 @@ describe('autocmd DirChanged', function() before_each(function() clear() - command('autocmd DirChanged * let [g:getcwd_rv, g:event, g:amatch, g:cdcount] ' - ..' = [getcwd(), copy(v:event), expand(""), 1 + get(g:, "cdcount", 0)]' - ..[[ | let g:event['cwd'] = substitute(g:event['cwd'], '\\', '/', 'g') ]]) + command('autocmd DirChanged * let [g:getcwd, g:ev, g:amatch, g:cdcount] ' + ..' = [getcwd(), copy(v:event), expand(""), 1 + get(g:, "cdcount", 0)]') + -- Normalize path separators. + command([[autocmd DirChanged * let g:ev['cwd'] = substitute(g:ev['cwd'], '\\', '/', 'g')]]) + command([[autocmd DirChanged * let g:getcwd = substitute(g:getcwd, '\\', '/', 'g')]]) end) it('sets v:event', function() command('lcd '..dirs[1]) - eq({cwd=dirs[1], scope='window'}, eval('g:event')) + eq({cwd=dirs[1], scope='window'}, eval('g:ev')) eq(1, eval('g:cdcount')) command('tcd '..dirs[2]) - eq({cwd=dirs[2], scope='tab'}, eval('g:event')) + eq({cwd=dirs[2], scope='tab'}, eval('g:ev')) eq(2, eval('g:cdcount')) command('cd '..dirs[3]) - eq({cwd=dirs[3], scope='global'}, eval('g:event')) + eq({cwd=dirs[3], scope='global'}, eval('g:ev')) eq(3, eval('g:cdcount')) end) it('sets getcwd() during event #6260', function() command('lcd '..dirs[1]) - eq(dirs[1], eval('g:getcwd_rv')) + eq(dirs[1], eval('g:getcwd')) command('tcd '..dirs[2]) - eq(dirs[2], eval('g:getcwd_rv')) + eq(dirs[2], eval('g:getcwd')) command('cd '..dirs[3]) - eq(dirs[3], eval('g:getcwd_rv')) + eq(dirs[3], eval('g:getcwd')) end) it('disallows recursion', function() @@ -55,7 +57,7 @@ describe('autocmd DirChanged', function() -- Set up a _nested_ handler. command('autocmd DirChanged * nested lcd '..dirs[3]) command('lcd '..dirs[1]) - eq({cwd=dirs[1], scope='window'}, eval('g:event')) + eq({cwd=dirs[1], scope='window'}, eval('g:ev')) eq(1, eval('g:cdcount')) -- autocmd changed to dirs[3], but did NOT trigger another DirChanged. eq(dirs[3], eval('getcwd()')) @@ -73,22 +75,22 @@ describe('autocmd DirChanged', function() end) it('does not trigger if :cd fails', function() - command('let g:event = {}') + command('let g:ev = {}') local status1, err1 = pcall(function() command('lcd '..dirs[1] .. '/doesnotexist') end) - eq({}, eval('g:event')) + eq({}, eval('g:ev')) local status2, err2 = pcall(function() command('lcd '..dirs[2] .. '/doesnotexist') end) - eq({}, eval('g:event')) + eq({}, eval('g:ev')) local status3, err3 = pcall(function() command('lcd '..dirs[3] .. '/doesnotexist') end) - eq({}, eval('g:event')) + eq({}, eval('g:ev')) eq(false, status1) eq(false, status2) @@ -103,10 +105,12 @@ describe('autocmd DirChanged', function() command('set autochdir') command('split '..dirs[1]..'/foo') - eq({cwd=dirs[1], scope='window'}, eval('g:event')) + eq({cwd=dirs[1], scope='window'}, eval('g:ev')) command('split '..dirs[2]..'/bar') - eq({cwd=dirs[2], scope='window'}, eval('g:event')) + eq({cwd=dirs[2], scope='window'}, eval('g:ev')) + + eq(2, eval('g:cdcount')) end) it("is triggered by switching to win/tab with different CWD #6054", function() @@ -117,16 +121,16 @@ describe('autocmd DirChanged', function() command('lcd '..dirs[1]) command('2wincmd w') -- window 2 - eq({cwd=dirs[2], scope='window'}, eval('g:event')) + eq({cwd=dirs[2], scope='window'}, eval('g:ev')) eq(4, eval('g:cdcount')) command('tabnew') -- tab 2 (tab-local CWD) eq(4, eval('g:cdcount')) -- same CWD, no DirChanged event command('tcd '..dirs[3]) command('tabnext') -- tab 1 (no tab-local CWD) - eq({cwd=dirs[2], scope='window'}, eval('g:event')) + eq({cwd=dirs[2], scope='window'}, eval('g:ev')) command('tabnext') -- tab 2 - eq({cwd=dirs[3], scope='tab'}, eval('g:event')) + eq({cwd=dirs[3], scope='tab'}, eval('g:ev')) eq(7, eval('g:cdcount')) command('tabnext') -- tab 1 @@ -134,21 +138,20 @@ describe('autocmd DirChanged', function() eq(9, eval('g:cdcount')) command('tabnext') -- tab 2 (has the *same* CWD) eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event - end) it('is triggered by nvim_set_current_dir()', function() request('nvim_set_current_dir', dirs[1]) - eq({cwd=dirs[1], scope='global'}, eval('g:event')) + eq({cwd=dirs[1], scope='global'}, eval('g:ev')) request('nvim_set_current_dir', dirs[2]) - eq({cwd=dirs[2], scope='global'}, eval('g:event')) + eq({cwd=dirs[2], scope='global'}, eval('g:ev')) local status, err = pcall(function() request('nvim_set_current_dir', '/doesnotexist') end) eq(false, status) eq('Failed to change directory', string.match(err, ': (.*)')) - eq({cwd=dirs[2], scope='global'}, eval('g:event')) + eq({cwd=dirs[2], scope='global'}, eval('g:ev')) end) end) -- cgit