summaryrefslogtreecommitdiffstats
path: root/src/ex_docmd.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-12-16 15:38:02 +0100
committerBram Moolenaar <Bram@vim.org>2018-12-16 15:38:02 +0100
commit2caad3fbbdbf1486a176c9f6bfbc3d9be90e09f7 (patch)
treef8c0b685281d64e985fd59046f1c12df66ca85bb /src/ex_docmd.c
parent4efe73b478d3ba689078da502fd96f45204ff1f5 (diff)
patch 8.1.0602: DirChanged is also triggered when directory didn't changev8.1.0602
Problem: DirChanged is also triggered when the directory didn't change. (Daniel Hahler) Solution: Compare the current with the new directory. (closes #3697)
Diffstat (limited to 'src/ex_docmd.c')
-rw-r--r--src/ex_docmd.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index c738d0798c..e700f2ed43 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -9126,8 +9126,9 @@ post_chdir(int local)
void
ex_cd(exarg_T *eap)
{
- char_u *new_dir;
- char_u *tofree;
+ char_u *new_dir;
+ char_u *tofree;
+ int dir_differs;
new_dir = eap->arg;
#if !defined(UNIX) && !defined(VMS)
@@ -9183,7 +9184,9 @@ ex_cd(exarg_T *eap)
new_dir = NameBuff;
}
#endif
- if (new_dir == NULL || vim_chdir(new_dir))
+ dir_differs = new_dir == NULL || prev_dir == NULL
+ || STRCMP(prev_dir, new_dir) != 0;
+ if (new_dir == NULL || (dir_differs && vim_chdir(new_dir)))
EMSG(_(e_failed));
else
{
@@ -9195,9 +9198,11 @@ ex_cd(exarg_T *eap)
/* Echo the new current directory if the command was typed. */
if (KeyTyped || p_verbose >= 5)
ex_pwd(eap);
- apply_autocmds(EVENT_DIRCHANGED,
- is_local_chdir ? (char_u *)"window" : (char_u *)"global",
- new_dir, FALSE, curbuf);
+
+ if (dir_differs)
+ apply_autocmds(EVENT_DIRCHANGED,
+ is_local_chdir ? (char_u *)"window" : (char_u *)"global",
+ new_dir, FALSE, curbuf);
}
vim_free(tofree);
}