diff options
Diffstat (limited to 'src/ex_docmd.c')
-rw-r--r-- | src/ex_docmd.c | 53 |
1 files changed, 32 insertions, 21 deletions
diff --git a/src/ex_docmd.c b/src/ex_docmd.c index 056339e7e..b6fc37668 100644 --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -8182,6 +8182,37 @@ free_cd_dir() } #endif +/* + * Deal with the side effects of changing the current directory. + * When "local" is TRUE then this was after an ":lcd" command. + */ + void +post_chdir(local) + int local; +{ + vim_free(curwin->w_localdir); + if (local) + { + /* If still in global directory, need to remember current + * directory as global directory. */ + if (globaldir == NULL && prev_dir != NULL) + globaldir = vim_strsave(prev_dir); + /* Remember this local directory for the window. */ + if (mch_dirname(NameBuff, MAXPATHL) == OK) + curwin->w_localdir = vim_strsave(NameBuff); + } + else + { + /* We are now in the global directory, no need to remember its + * name. */ + vim_free(globaldir); + globaldir = NULL; + curwin->w_localdir = NULL; + } + + shorten_fnames(TRUE); +} + /* * ":cd", ":lcd", ":chdir" and ":lchdir". @@ -8253,27 +8284,7 @@ ex_cd(eap) EMSG(_(e_failed)); else { - vim_free(curwin->w_localdir); - if (eap->cmdidx == CMD_lcd || eap->cmdidx == CMD_lchdir) - { - /* If still in global directory, need to remember current - * directory as global directory. */ - if (globaldir == NULL && prev_dir != NULL) - globaldir = vim_strsave(prev_dir); - /* Remember this local directory for the window. */ - if (mch_dirname(NameBuff, MAXPATHL) == OK) - curwin->w_localdir = vim_strsave(NameBuff); - } - else - { - /* We are now in the global directory, no need to remember its - * name. */ - vim_free(globaldir); - globaldir = NULL; - curwin->w_localdir = NULL; - } - - shorten_fnames(TRUE); + post_chdir(eap->cmdidx == CMD_lcd || eap->cmdidx == CMD_lchdir); /* Echo the new current directory if the command was typed. */ if (KeyTyped || p_verbose >= 5) |