aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/window.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/window.c')
-rw-r--r--src/nvim/window.c88
1 files changed, 52 insertions, 36 deletions
diff --git a/src/nvim/window.c b/src/nvim/window.c
index 73a60b2e04..6c9d3554f1 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -161,13 +161,18 @@ newwindow:
/* cursor to preview window */
case 'P':
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
- if (wp->w_p_pvw)
+ wp = NULL;
+ FOR_ALL_WINDOWS_IN_TAB(wp2, curtab) {
+ if (wp2->w_p_pvw) {
+ wp = wp2;
break;
- if (wp == NULL)
+ }
+ }
+ if (wp == NULL) {
EMSG(_("E441: There is no preview window"));
- else
+ } else {
win_goto(wp);
+ }
break;
/* close all but current window */
@@ -2998,8 +3003,7 @@ void free_tabpage(tabpage_T *tp)
hash_init(&tp->tp_vars->dv_hashtab);
unref_var_dict(tp->tp_vars);
-
- xfree(tp->localdir); // Free tab-local working directory
+ xfree(tp->tp_localdir);
xfree(tp);
}
@@ -3025,7 +3029,7 @@ int win_new_tabpage(int after, char_u *filename)
return FAIL;
}
- newtp->localdir = tp->localdir ? vim_strsave(tp->localdir) : NULL;
+ newtp->tp_localdir = tp->tp_localdir ? vim_strsave(tp->tp_localdir) : NULL;
curtab = newtp;
@@ -3362,15 +3366,20 @@ void tabpage_move(int nr)
tp_dst = tp;
- /* Remove the current tab page from the list of tab pages. */
- if (curtab == first_tabpage)
+ // Remove the current tab page from the list of tab pages.
+ if (curtab == first_tabpage) {
first_tabpage = curtab->tp_next;
- else {
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
- if (tp->tp_next == curtab)
+ } else {
+ tp = NULL;
+ FOR_ALL_TABS(tp2) {
+ if (tp2->tp_next == curtab) {
+ tp = tp2;
break;
- if (tp == NULL) /* "cannot happen" */
+ }
+ }
+ if (tp == NULL) { // "cannot happen"
return;
+ }
tp->tp_next = curtab->tp_next;
}
@@ -3617,28 +3626,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, of the tab
- // or NULL.
- char_u *new_dir = curwin->w_localdir ? curwin->w_localdir : curtab->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);
@@ -5753,10 +5772,11 @@ int win_getid(typval_T *argvars)
if (argvars[1].v_type == VAR_UNKNOWN) {
wp = firstwin;
} else {
- tabpage_T *tp;
+ tabpage_T *tp = NULL;
int tabnr = get_tv_number(&argvars[1]);
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) {
+ FOR_ALL_TABS(tp2) {
if (--tabnr == 0) {
+ tp = tp2;
break;
}
}
@@ -5833,11 +5853,10 @@ win_T * win_id2wp(typval_T *argvars)
int win_id2win(typval_T *argvars)
{
- win_T *wp;
int nr = 1;
int id = get_tv_number(&argvars[0]);
- for (wp = firstwin; wp != NULL; wp = wp->w_next) {
+ FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
if (wp->handle == id) {
return nr;
}
@@ -5850,12 +5869,9 @@ void win_findbuf(typval_T *argvars, list_T *list)
{
int bufnr = get_tv_number(&argvars[0]);
- for (tabpage_T *tp = first_tabpage; tp != NULL; tp = tp->tp_next) {
- for (win_T *wp = tp == curtab ? firstwin : tp->tp_firstwin;
- wp != NULL; wp = wp->w_next) {
- if (wp->w_buffer->b_fnum == bufnr) {
- list_append_number(list, wp->handle);
- }
+ FOR_ALL_TAB_WINDOWS(tp, wp) {
+ if (wp->w_buffer->b_fnum == bufnr) {
+ list_append_number(list, wp->handle);
}
}
}