mirror of
https://github.com/neovim/neovim.git
synced 2024-12-31 17:13:26 -07:00
DirChanged: set <amatch> (#5961)
Also: - test that DirChanged is not recursive - fix 'not trigger if :cd fails' test on Windows
This commit is contained in:
parent
a062cd4ce5
commit
be4c896845
@ -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*
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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'))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user