aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/file_search.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2021-10-17 22:04:53 +0800
committerzeertzjq <zeertzjq@outlook.com>2021-10-17 22:04:53 +0800
commit920473d2f228fb33c63c092c825b182a7434f25f (patch)
tree66286a9b6d460810d0d9d596f593c501a953be2c /src/nvim/file_search.c
parent30af69509dc91552dc41451857b18907f018c1bd (diff)
downloadrneovim-920473d2f228fb33c63c092c825b182a7434f25f.tar.gz
rneovim-920473d2f228fb33c63c092c825b182a7434f25f.tar.bz2
rneovim-920473d2f228fb33c63c092c825b182a7434f25f.zip
vim-patch:8.0.1459: cannot handle change of directory
Problem: Cannot handle change of directory. Solution: Add the DirChanged autocommand event. (Andy Massimino, closes vim/vim#888) Avoid changing directory for 'autochdir' too often. https://github.com/vim/vim/commit/b7407d3fc9496f9048fb65ab17b5ba3444965c0e Only add "auto" pattern. "window" and "global" are already implemented. Skip `Test_dirchanged_auto` using `CheckFunction test_autochdir`. Part of PR #15952. More information can be found there. N/A patches for version.c: vim-patch:8.0.1460: missing file in patch Problem: Missing file in patch. Solution: Add changes to missing file. https://github.com/vim/vim/commit/b5cb65ba2bcc6bbc6d2798a2dea18b95f0b38f5e vim-patch:8.0.1461: missing another file in patch Problem: Missing another file in patch. Solution: Add changes to missing file. https://github.com/vim/vim/commit/15833239a4131279935a4bd574b74fe3a2b0f49f
Diffstat (limited to 'src/nvim/file_search.c')
-rw-r--r--src/nvim/file_search.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c
index 5458d8acf2..e7c4785beb 100644
--- a/src/nvim/file_search.c
+++ b/src/nvim/file_search.c
@@ -1590,7 +1590,7 @@ theend:
return file_name;
}
-void do_autocmd_dirchanged(char *new_dir, CdScope scope, bool changed_window)
+void do_autocmd_dirchanged(char *new_dir, CdScope scope, CdCause cause)
{
static bool recursive = false;
@@ -1621,10 +1621,22 @@ void do_autocmd_dirchanged(char *new_dir, CdScope scope, bool changed_window)
}
tv_dict_add_str(dict, S_LEN("scope"), buf); // -V614
- tv_dict_add_str(dict, S_LEN("cwd"), new_dir);
- tv_dict_add_bool(dict, S_LEN("changed_window"), changed_window);
+ tv_dict_add_str(dict, S_LEN("cwd"), new_dir);
+ tv_dict_add_bool(dict, S_LEN("changed_window"), cause == kCdCauseWindow);
tv_dict_set_keys_readonly(dict);
+ switch (cause) {
+ case kCdCauseManual:
+ case kCdCauseWindow:
+ break;
+ case kCdCauseAuto:
+ snprintf(buf, sizeof(buf), "auto");
+ break;
+ case kCdCauseOther:
+ // Should never happen.
+ abort();
+ }
+
apply_autocmds(EVENT_DIRCHANGED, (char_u *)buf, (char_u *)new_dir, false,
curbuf);
@@ -1636,7 +1648,7 @@ void do_autocmd_dirchanged(char *new_dir, CdScope scope, bool changed_window)
/// Change to a file's directory.
/// Caller must call shorten_fnames()!
/// @return OK or FAIL
-int vim_chdirfile(char_u *fname)
+int vim_chdirfile(char_u *fname, CdCause cause)
{
char dir[MAXPATHL];
@@ -1654,8 +1666,8 @@ int vim_chdirfile(char_u *fname)
#ifdef BACKSLASH_IN_FILENAME
slash_adjust((char_u *)dir);
#endif
- if (!strequal(dir, (char *)NameBuff)) {
- do_autocmd_dirchanged(dir, kCdScopeWindow, false);
+ if (cause != kCdCauseOther && !strequal(dir, (char *)NameBuff)) {
+ do_autocmd_dirchanged(dir, kCdScopeWindow, cause);
}
return OK;