DirChanged: trigger when switching scopes

Closes #6054
This commit is contained in:
Justin M. Keyes
2017-03-12 12:11:10 +01:00
parent 99a1a58c66
commit d9fcbc2cfb
5 changed files with 63 additions and 18 deletions

View File

@@ -3616,28 +3616,38 @@ static void win_enter_ext(win_T *wp, bool undo_sync, int curwin_invalid,
curwin->w_cursor.coladd = 0;
changed_line_abv_curs(); /* assume cursor position needs updating */
// The new directory is either the local directory of the window, tab or NULL.
char_u *new_dir = curwin->w_localdir
? curwin->w_localdir : curtab->tp_localdir;
// New directory is either the local directory of the window, tab or NULL.
char *new_dir = (char *)(curwin->w_localdir
? curwin->w_localdir : curtab->tp_localdir);
char cwd[MAXPATHL];
if (os_dirname((char_u *)cwd, MAXPATHL) != OK) {
cwd[0] = NUL;
}
if (new_dir) {
// Window/tab has a local directory: Save current directory as global
// directory (unless that was done already) and change to the local
// directory.
// (unless that was done already) and change to the local directory.
if (globaldir == NULL) {
char_u cwd[MAXPATHL];
if (os_dirname(cwd, MAXPATHL) == OK) {
globaldir = vim_strsave(cwd);
if (cwd[0] != NUL) {
globaldir = (char_u *)xstrdup(cwd);
}
}
if (os_chdir((char *)new_dir) == 0) {
if (os_chdir(new_dir) == 0) {
if (!p_acd && !strequal(new_dir, cwd)) {
do_autocmd_dirchanged(new_dir, curwin->w_localdir
? kCdScopeWindow : kCdScopeTab);
}
shorten_fnames(true);
}
} else if (globaldir != NULL) {
/* Window doesn't have a local directory and we are not in the global
* directory: Change to the global directory. */
ignored = os_chdir((char *)globaldir);
// Window doesn't have a local directory and we are not in the global
// directory: Change to the global directory.
if (os_chdir((char *)globaldir) == 0) {
if (!p_acd && !strequal((char *)globaldir, cwd)) {
do_autocmd_dirchanged((char *)globaldir, kCdScopeGlobal);
}
}
xfree(globaldir);
globaldir = NULL;
shorten_fnames(TRUE);