diff options
author | Marco Hinz <mh.codebro@gmail.com> | 2019-04-13 12:50:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-13 12:50:36 +0200 |
commit | 5f996e36d102beeb76848021fe0ded5107c8f24d (patch) | |
tree | 27da72da722367d870bb4aecdf4deeab60664c44 | |
parent | d08692a8246039b938b5645a6c01b4ff7f51671e (diff) | |
download | rneovim-5f996e36d102beeb76848021fe0ded5107c8f24d.tar.gz rneovim-5f996e36d102beeb76848021fe0ded5107c8f24d.tar.bz2 rneovim-5f996e36d102beeb76848021fe0ded5107c8f24d.zip |
options: properly reset directories on 'autochdir' (#9894)
Fixes https://github.com/neovim/neovim/issues/9892
-rw-r--r-- | src/nvim/api/vim.c | 2 | ||||
-rw-r--r-- | src/nvim/buffer.c | 1 | ||||
-rw-r--r-- | src/nvim/ex_docmd.c | 9 | ||||
-rw-r--r-- | test/functional/ex_cmds/cd_spec.lua | 9 |
4 files changed, 17 insertions, 4 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index f56d37af90..b8bd3dd63a 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -690,7 +690,7 @@ void nvim_set_current_dir(String dir, Error *err) return; } - post_chdir(kCdScopeGlobal); + post_chdir(kCdScopeGlobal, true); try_end(err); } diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index d7a16de299..b9c4c4d544 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -1620,6 +1620,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); } } diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 037b5dec7f..895fbcd95e 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -7241,7 +7241,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); @@ -7281,7 +7281,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`. @@ -7343,7 +7346,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); diff --git a/test/functional/ex_cmds/cd_spec.lua b/test/functional/ex_cmds/cd_spec.lua index bc2b365b30..283fcf9672 100644 --- a/test/functional/ex_cmds/cd_spec.lua +++ b/test/functional/ex_cmds/cd_spec.lua @@ -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) |