mirror of
https://github.com/neovim/neovim.git
synced 2025-09-25 04:28:33 +00:00
New event: DirChanged
This commit is contained in:
@@ -28,6 +28,7 @@ return {
|
|||||||
'CursorHoldI', -- idem, in Insert mode
|
'CursorHoldI', -- idem, in Insert mode
|
||||||
'CursorMoved', -- cursor was moved
|
'CursorMoved', -- cursor was moved
|
||||||
'CursorMovedI', -- cursor was moved in Insert mode
|
'CursorMovedI', -- cursor was moved in Insert mode
|
||||||
|
'DirChanged', -- directory changed
|
||||||
'EncodingChanged', -- after changing the 'encoding' option
|
'EncodingChanged', -- after changing the 'encoding' option
|
||||||
'FileAppendCmd', -- append to a file using command
|
'FileAppendCmd', -- append to a file using command
|
||||||
'FileAppendPost', -- after appending to a file
|
'FileAppendPost', -- after appending to a file
|
||||||
@@ -101,6 +102,7 @@ return {
|
|||||||
-- List of neovim-specific events or aliases for the purpose of generating
|
-- List of neovim-specific events or aliases for the purpose of generating
|
||||||
-- syntax file
|
-- syntax file
|
||||||
neovim_specific = {
|
neovim_specific = {
|
||||||
|
DirChanged=true,
|
||||||
TabClosed=true,
|
TabClosed=true,
|
||||||
TabNew=true,
|
TabNew=true,
|
||||||
TabNewEntered=true,
|
TabNewEntered=true,
|
||||||
|
@@ -6949,6 +6949,35 @@ void free_cd_dir(void)
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static void apply_autocmd_dirchanged(char_u *new_dir, CdScope scope)
|
||||||
|
{
|
||||||
|
dict_T *dict = get_vim_var_dict(VV_EVENT);
|
||||||
|
char buf[8];
|
||||||
|
|
||||||
|
switch (scope) {
|
||||||
|
case kCdScopeGlobal:
|
||||||
|
snprintf(buf, sizeof(buf), "global");
|
||||||
|
break;
|
||||||
|
case kCdScopeTab:
|
||||||
|
snprintf(buf, sizeof(buf), "tab");
|
||||||
|
break;
|
||||||
|
case kCdScopeWindow:
|
||||||
|
snprintf(buf, sizeof(buf), "window");
|
||||||
|
break;
|
||||||
|
case kCdScopeInvalid:
|
||||||
|
// Should never happen.
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
dict_add_nr_str(dict, "scope", 0L, (char_u *)buf);
|
||||||
|
dict_add_nr_str(dict, "cwd", 0L, new_dir);
|
||||||
|
dict_set_keys_readonly(dict);
|
||||||
|
|
||||||
|
apply_autocmds(EVENT_DIRCHANGED, NULL, new_dir, false, NULL);
|
||||||
|
|
||||||
|
dict_clear(dict);
|
||||||
|
}
|
||||||
|
|
||||||
/// 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).
|
||||||
@@ -6972,6 +7001,8 @@ void post_chdir(CdScope scope)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apply_autocmd_dirchanged(new_dir, scope);
|
||||||
|
|
||||||
switch (scope) {
|
switch (scope) {
|
||||||
case kCdScopeGlobal:
|
case kCdScopeGlobal:
|
||||||
// We are now in the global directory, no need to remember its name.
|
// We are now in the global directory, no need to remember its name.
|
||||||
@@ -6998,8 +7029,6 @@ void post_chdir(CdScope scope)
|
|||||||
shorten_fnames(TRUE);
|
shorten_fnames(TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// `:cd`, `:tcd`, `:lcd`, `:chdir`, `:tchdir` and `:lchdir`.
|
/// `:cd`, `:tcd`, `:lcd`, `:chdir`, `:tchdir` and `:lchdir`.
|
||||||
void ex_cd(exarg_T *eap)
|
void ex_cd(exarg_T *eap)
|
||||||
{
|
{
|
||||||
@@ -7061,8 +7090,8 @@ void ex_cd(exarg_T *eap)
|
|||||||
|
|
||||||
post_chdir(scope);
|
post_chdir(scope);
|
||||||
|
|
||||||
/* 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);
|
||||||
}
|
}
|
||||||
xfree(tofree);
|
xfree(tofree);
|
||||||
|
Reference in New Issue
Block a user