aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/file_search.c
diff options
context:
space:
mode:
authorMarco Hinz <mh.codebro@gmail.com>2017-01-16 13:36:16 +0100
committerGitHub <noreply@github.com>2017-01-16 13:36:16 +0100
commit340f79b4b8f1021f4a3b88265ced2ce39d0e2e03 (patch)
tree71509fab0581f8454272493e38fd0018a32c3c5f /src/nvim/file_search.c
parentfa94c4c2d917b70df443ba0ebcd87da35dc1bb30 (diff)
parent1f7a119f5efc13fbce6446bf268c2e0f9d753147 (diff)
downloadrneovim-340f79b4b8f1021f4a3b88265ced2ce39d0e2e03.tar.gz
rneovim-340f79b4b8f1021f4a3b88265ced2ce39d0e2e03.tar.bz2
rneovim-340f79b4b8f1021f4a3b88265ced2ce39d0e2e03.zip
Merge #5928 'New event: DirChanged'
Diffstat (limited to 'src/nvim/file_search.c')
-rw-r--r--src/nvim/file_search.c56
1 files changed, 54 insertions, 2 deletions
diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c
index 2ac8e27047..eb93921bb0 100644
--- a/src/nvim/file_search.c
+++ b/src/nvim/file_search.c
@@ -48,6 +48,7 @@
#include <limits.h>
#include "nvim/vim.h"
+#include "nvim/eval.h"
#include "nvim/ascii.h"
#include "nvim/file_search.h"
#include "nvim/charset.h"
@@ -1522,6 +1523,47 @@ theend:
return file_name;
}
+static void do_autocmd_dirchanged(char_u *new_dir, CdScope scope)
+{
+ static bool recursive = false;
+
+ if (recursive || !has_event(EVENT_DIRCHANGED)) {
+ // No autocommand was defined or we changed
+ // the directory from this autocommand.
+ return;
+ }
+
+ recursive = true;
+
+ 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);
+
+ recursive = false;
+}
+
/// Change to a file's directory.
/// Caller must call shorten_fnames()!
/// @return OK or FAIL
@@ -1531,18 +1573,28 @@ int vim_chdirfile(char_u *fname)
STRLCPY(dir, fname, MAXPATHL);
*path_tail_with_sep(dir) = NUL;
- return os_chdir((char *)dir) == 0 ? OK : FAIL;
+ if (os_chdir((char *)dir) != 0) {
+ return FAIL;
+ }
+ do_autocmd_dirchanged(dir, kCdScopeWindow);
+
+ return OK;
}
/// Change directory to "new_dir". Search 'cdpath' for relative directory names.
-int vim_chdir(char_u *new_dir)
+int vim_chdir(char_u *new_dir, CdScope scope)
{
char_u *dir_name = find_directory_in_path(new_dir, STRLEN(new_dir),
FNAME_MESS, curbuf->b_ffname);
if (dir_name == NULL) {
return -1;
}
+
int r = os_chdir((char *)dir_name);
+ if (r == 0) {
+ do_autocmd_dirchanged(dir_name, scope);
+ }
+
xfree(dir_name);
return r;
}