aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/file_search.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-02-11 12:44:47 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-02-11 12:55:58 +0800
commit059d36e326e31fc9bc6055d7c999f86d94fa9bd5 (patch)
tree53577f4456663a3315e0d485914c3a4d6c4e2f42 /src/nvim/file_search.c
parent851252f79ddaaca5456b287342cd36130c76ff38 (diff)
downloadrneovim-059d36e326e31fc9bc6055d7c999f86d94fa9bd5.tar.gz
rneovim-059d36e326e31fc9bc6055d7c999f86d94fa9bd5.tar.bz2
rneovim-059d36e326e31fc9bc6055d7c999f86d94fa9bd5.zip
feat(events): add DirChangedPre
In Nvim, like DirChanged, this also triggers when switching windows. This marks Vim patch 8.2.4335 as ported. vim-patch:8.2.4335: no autocommand event triggered before changing directory Problem: No autocommand event triggered before changing directory. (Ronnie Magatti) Solution: Add DirChangedPre. (closes vim/vim#9721) https://github.com/vim/vim/commit/28e8f73ae2d90009fd62cd60f97c2643ba44de68
Diffstat (limited to 'src/nvim/file_search.c')
-rw-r--r--src/nvim/file_search.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c
index 25dbf680de..d0f7a91d6c 100644
--- a/src/nvim/file_search.c
+++ b/src/nvim/file_search.c
@@ -1600,11 +1600,13 @@ theend:
return file_name;
}
-void do_autocmd_dirchanged(char *new_dir, CdScope scope, CdCause cause)
+void do_autocmd_dirchanged(char *new_dir, CdScope scope, CdCause cause, bool pre)
{
static bool recursive = false;
- if (recursive || !has_event(EVENT_DIRCHANGED)) {
+ event_T event = pre ? EVENT_DIRCHANGEDPRE : EVENT_DIRCHANGED;
+
+ if (recursive || !has_event(event)) {
// No autocommand was defined or we changed
// the directory from this autocommand.
return;
@@ -1638,8 +1640,12 @@ void do_autocmd_dirchanged(char *new_dir, CdScope scope, CdCause cause)
new_dir = new_dir_buf;
#endif
+ if (pre) {
+ tv_dict_add_str(dict, S_LEN("directory"), new_dir);
+ } else {
+ tv_dict_add_str(dict, S_LEN("cwd"), new_dir);
+ }
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"), cause == kCdCauseWindow);
tv_dict_set_keys_readonly(dict);
@@ -1655,8 +1661,7 @@ void do_autocmd_dirchanged(char *new_dir, CdScope scope, CdCause cause)
abort();
}
- apply_autocmds(EVENT_DIRCHANGED, (char_u *)buf, (char_u *)new_dir, false,
- curbuf);
+ apply_autocmds(event, (char_u *)buf, (char_u *)new_dir, false, curbuf);
restore_v_event(dict, &save_v_event);
@@ -1682,12 +1687,16 @@ int vim_chdirfile(char_u *fname, CdCause cause)
return OK;
}
+ if (cause != kCdCauseOther) {
+ do_autocmd_dirchanged(dir, kCdScopeWindow, cause, true);
+ }
+
if (os_chdir(dir) != 0) {
return FAIL;
}
if (cause != kCdCauseOther) {
- do_autocmd_dirchanged(dir, kCdScopeWindow, cause);
+ do_autocmd_dirchanged(dir, kCdScopeWindow, cause, false);
}
return OK;