mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 11:58:17 +00:00
options: properly reset directories on 'autochdir' (#9894)
Fixes https://github.com/neovim/neovim/issues/9892
This commit is contained in:
@@ -690,7 +690,7 @@ void nvim_set_current_dir(String dir, Error *err)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
post_chdir(kCdScopeGlobal);
|
post_chdir(kCdScopeGlobal, true);
|
||||||
try_end(err);
|
try_end(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1620,6 +1620,7 @@ void do_autochdir(void)
|
|||||||
if (starting == 0
|
if (starting == 0
|
||||||
&& curbuf->b_ffname != NULL
|
&& curbuf->b_ffname != NULL
|
||||||
&& vim_chdirfile(curbuf->b_ffname) == OK) {
|
&& vim_chdirfile(curbuf->b_ffname) == OK) {
|
||||||
|
post_chdir(kCdScopeGlobal, false);
|
||||||
shorten_fnames(true);
|
shorten_fnames(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7241,7 +7241,7 @@ void free_cd_dir(void)
|
|||||||
/// Deal with the side effects of changing the current directory.
|
/// Deal with the side effects of changing the current directory.
|
||||||
///
|
///
|
||||||
/// @param scope Scope of the function call (global, tab or window).
|
/// @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.
|
// Always overwrite the window-local CWD.
|
||||||
xfree(curwin->w_localdir);
|
xfree(curwin->w_localdir);
|
||||||
@@ -7281,7 +7281,10 @@ void post_chdir(CdScope scope)
|
|||||||
}
|
}
|
||||||
|
|
||||||
shorten_fnames(true);
|
shorten_fnames(true);
|
||||||
do_autocmd_dirchanged(cwd, scope);
|
|
||||||
|
if (trigger_dirchanged) {
|
||||||
|
do_autocmd_dirchanged(cwd, scope);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `:cd`, `:tcd`, `:lcd`, `:chdir`, `:tchdir` and `:lchdir`.
|
/// `:cd`, `:tcd`, `:lcd`, `:chdir`, `:tchdir` and `:lchdir`.
|
||||||
@@ -7343,7 +7346,7 @@ void ex_cd(exarg_T *eap)
|
|||||||
if (vim_chdir(new_dir, scope)) {
|
if (vim_chdir(new_dir, scope)) {
|
||||||
EMSG(_(e_failed));
|
EMSG(_(e_failed));
|
||||||
} else {
|
} else {
|
||||||
post_chdir(scope);
|
post_chdir(scope, true);
|
||||||
// Echo the new current directory if the command was typed.
|
// Echo the new current directory if the command was typed.
|
||||||
if (KeyTyped || p_verbose >= 5) {
|
if (KeyTyped || p_verbose >= 5) {
|
||||||
ex_pwd(eap);
|
ex_pwd(eap);
|
||||||
|
@@ -286,6 +286,15 @@ describe("getcwd()", function ()
|
|||||||
command("call delete('../"..directories.global.."', 'd')")
|
command("call delete('../"..directories.global.."', 'd')")
|
||||||
eq("", helpers.eval("getcwd()"))
|
eq("", helpers.eval("getcwd()"))
|
||||||
end)
|
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)
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user