options: properly reset directories on 'autochdir' (#9894)

Fixes https://github.com/neovim/neovim/issues/9892
This commit is contained in:
Marco Hinz 2019-04-13 12:50:36 +02:00 committed by Justin M. Keyes
parent 9a5488c2a6
commit f891131c6b
4 changed files with 17 additions and 4 deletions

View File

@ -594,7 +594,7 @@ void nvim_set_current_dir(String dir, Error *err)
return;
}
post_chdir(kCdScopeGlobal);
post_chdir(kCdScopeGlobal, true);
try_end(err);
}

View File

@ -1559,6 +1559,7 @@ void do_autochdir(void)
if (starting == 0
&& curbuf->b_ffname != NULL
&& vim_chdirfile(curbuf->b_ffname) == OK) {
post_chdir(kCdScopeGlobal, false);
shorten_fnames(true);
}
}

View File

@ -7218,7 +7218,7 @@ void free_cd_dir(void)
/// Deal with the side effects of changing the current directory.
///
/// @param scope Scope of the function call (global, tab or window).
void post_chdir(CdScope scope)
void post_chdir(CdScope scope, bool trigger_dirchanged)
{
// Always overwrite the window-local CWD.
xfree(curwin->w_localdir);
@ -7258,7 +7258,10 @@ void post_chdir(CdScope scope)
}
shorten_fnames(true);
do_autocmd_dirchanged(cwd, scope);
if (trigger_dirchanged) {
do_autocmd_dirchanged(cwd, scope);
}
}
/// `:cd`, `:tcd`, `:lcd`, `:chdir`, `:tchdir` and `:lchdir`.
@ -7320,7 +7323,7 @@ void ex_cd(exarg_T *eap)
if (vim_chdir(new_dir, scope)) {
EMSG(_(e_failed));
} else {
post_chdir(scope);
post_chdir(scope, true);
// Echo the new current directory if the command was typed.
if (KeyTyped || p_verbose >= 5) {
ex_pwd(eap);

View File

@ -286,6 +286,15 @@ describe("getcwd()", function ()
command("call delete('../"..directories.global.."', 'd')")
eq("", helpers.eval("getcwd()"))
end)
it("works with 'autochdir' after local directory was set (#9892)", function()
local curdir = cwd()
command('lcd ' .. directories.global)
command('lcd -')
command('set autochdir')
command('edit ' .. directories.global .. '/foo')
eq(curdir .. pathsep .. directories.global, cwd())
end)
end)