diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2017-01-17 10:47:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-17 10:47:20 +0100 |
commit | be4c8968456231560f17736bf04b4c265a9d7dac (patch) | |
tree | 4e6880d137af4a5405217acabea5280c59e11925 | |
parent | a062cd4ce58ba9aca6fdce443b014c9c0949ecde (diff) | |
download | rneovim-be4c8968456231560f17736bf04b4c265a9d7dac.tar.gz rneovim-be4c8968456231560f17736bf04b4c265a9d7dac.tar.bz2 rneovim-be4c8968456231560f17736bf04b4c265a9d7dac.zip |
DirChanged: set <amatch> (#5961)
Also:
- test that DirChanged is not recursive
- fix 'not trigger if :cd fails' test on Windows
-rw-r--r-- | runtime/doc/autocmd.txt | 27 | ||||
-rw-r--r-- | src/nvim/file_search.c | 2 | ||||
-rw-r--r-- | test/functional/autocmd/dirchanged_spec.lua | 45 |
3 files changed, 47 insertions, 27 deletions
diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt index 320c821f21..180127cd52 100644 --- a/runtime/doc/autocmd.txt +++ b/runtime/doc/autocmd.txt @@ -273,10 +273,10 @@ Name triggered by ~ |VimLeave| before exiting Vim, after writing the shada file Various -|DirChanged| When the current working directory changed. +|DirChanged| after the |current-directory| was changed |FileChangedShell| Vim notices that a file changed since editing started -|FileChangedShellPost| After handling a file changed since editing started +|FileChangedShellPost| after handling a file changed since editing started |FileChangedRO| before making the first change to a read-only file |ShellCmdPost| after executing a shell command @@ -566,14 +566,10 @@ CursorMovedI After the cursor was moved in Insert mode. Not triggered when the popup menu is visible. Otherwise the same as CursorMoved. *DirChanged* -DirChanged When the current working directory was changed - using the |:cd| family of commands, - |nvim_set_current_dir()|, or on 'autochdir'. - The pattern must be * because its meaning may - change in the future. - It sets these |v:event| keys: - cwd: String (current working directory) - scope: String ("global", "tab", "window") +DirChanged After the |current-directory| was changed. + Sets these |v:event| keys: + cwd: current working directory + scope: "global", "tab", "window" Recursion is ignored. *FileAppendCmd* FileAppendCmd Before appending to a file. Should do the @@ -739,13 +735,12 @@ InsertCharPre When a character is typed in Insert mode, *TextYankPost* TextYankPost Just after a |yank| or |deleting| command, but not if the black hole register |quote_| is used nor - for |setreg()|. Pattern must be * because its - meaning may change in the future. + for |setreg()|. Pattern must be *. Sets these |v:event| keys: - operator - regcontents - regname - regtype + operator + regcontents + regname + regtype Recursion is ignored. It is not allowed to change the text |textlock|. *InsertEnter* diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index eb93921bb0..03cb504f17 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -1557,7 +1557,7 @@ static void do_autocmd_dirchanged(char_u *new_dir, CdScope scope) dict_add_nr_str(dict, "cwd", 0L, new_dir); dict_set_keys_readonly(dict); - apply_autocmds(EVENT_DIRCHANGED, NULL, new_dir, false, NULL); + apply_autocmds(EVENT_DIRCHANGED, (char_u *)buf, new_dir, false, NULL); dict_clear(dict); diff --git a/test/functional/autocmd/dirchanged_spec.lua b/test/functional/autocmd/dirchanged_spec.lua index 30a460bc4c..15196dbd44 100644 --- a/test/functional/autocmd/dirchanged_spec.lua +++ b/test/functional/autocmd/dirchanged_spec.lua @@ -7,8 +7,8 @@ local eq = h.eq local eval = h.eval local request = h.request -describe('DirChanged ->', function() - local curdir = lfs.currentdir() +describe('autocmd DirChanged', function() + local curdir = string.gsub(lfs.currentdir(), '\\', '/') local dirs = { curdir .. '/Xtest-functional-autocmd-dirchanged.dir1', curdir .. '/Xtest-functional-autocmd-dirchanged.dir2', @@ -20,21 +20,46 @@ describe('DirChanged ->', function() before_each(function() clear() - command('autocmd DirChanged * let g:event = copy(v:event)') + command('autocmd DirChanged * let [g:event, g:scope, g:cdcount] = [copy(v:event), expand("<amatch>"), 1 + get(g:, "cdcount", 0)]') end) - it('"autocmd DirChanged *" sets v:event for all :cd variants', function() + it('sets v:event', function() command('lcd '..dirs[1]) eq({cwd=dirs[1], scope='window'}, eval('g:event')) + eq(1, eval('g:cdcount')) command('tcd '..dirs[2]) eq({cwd=dirs[2], scope='tab'}, eval('g:event')) + eq(2, eval('g:cdcount')) command('cd '..dirs[3]) eq({cwd=dirs[3], scope='global'}, eval('g:event')) + eq(3, eval('g:cdcount')) end) - it('"autocmd DirChanged *" does not trigger for failing :cd variants', function() + it('disallows recursion', function() + command('set shellslash') + -- 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(1, eval('g:cdcount')) + -- autocmd changed to dirs[3], but did NOT trigger another DirChanged. + eq(dirs[3], eval('getcwd()')) + end) + + it('sets <amatch> to CWD "scope"', function() + command('lcd '..dirs[1]) + eq('window', eval('g:scope')) + + command('tcd '..dirs[2]) + eq('tab', eval('g:scope')) + + command('cd '..dirs[3]) + eq('global', eval('g:scope')) + end) + + it('does not trigger if :cd fails', function() command('let g:event = {}') local status1, err1 = pcall(function() @@ -56,12 +81,12 @@ describe('DirChanged ->', function() eq(false, status2) eq(false, status3) - eq('E344', string.match(err1, 'Vim.*:(.*):')) - eq('E344', string.match(err2, 'Vim.*:(.*):')) - eq('E344', string.match(err3, 'Vim.*:(.*):')) + eq('E344:', string.match(err1, "E%d*:")) + eq('E344:', string.match(err2, "E%d*:")) + eq('E344:', string.match(err3, "E%d*:")) end) - it("'autochdir' triggers DirChanged", function() + it("is triggered by 'autochdir'", function() command('set autochdir') command('split '..dirs[1]..'/foo') @@ -71,7 +96,7 @@ describe('DirChanged ->', function() eq({cwd=dirs[2], scope='window'}, eval('g:event')) end) - it('nvim_set_current_dir() triggers DirChanged', function() + 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')) |