vim-patch:7.4.2101

Problem:    Looping over windows, buffers and tab pages is inconsistant.
Solution:   Use FOR_ALL_ macros everywhere. (Yegappan Lakshmanan)

2932359000
This commit is contained in:
James McCoy
2017-03-10 16:13:37 -05:00
parent 5674057e3a
commit 564e9dc17f
10 changed files with 51 additions and 35 deletions

View File

@@ -4365,10 +4365,15 @@ void ex_help(exarg_T *eap)
) { ) {
if (cmdmod.tab != 0) if (cmdmod.tab != 0)
wp = NULL; wp = NULL;
else else {
for (wp = firstwin; wp != NULL; wp = wp->w_next) wp = NULL;
if (wp->w_buffer != NULL && wp->w_buffer->b_help) FOR_ALL_WINDOWS_IN_TAB(wp2, curtab) {
if (wp2->w_buffer != NULL && wp2->w_buffer->b_help) {
wp = wp2;
break; break;
}
}
}
if (wp != NULL && wp->w_buffer->b_nwindows > 0) if (wp != NULL && wp->w_buffer->b_nwindows > 0)
win_enter(wp, true); win_enter(wp, true);
else { else {

View File

@@ -5851,7 +5851,7 @@ static void ex_quit_all(exarg_T *eap)
*/ */
static void ex_close(exarg_T *eap) static void ex_close(exarg_T *eap)
{ {
win_T *win; win_T *win = NULL;
int winnr = 0; int winnr = 0;
if (cmdwin_type != 0) if (cmdwin_type != 0)
cmdwin_result = Ctrl_C; cmdwin_result = Ctrl_C;
@@ -5859,10 +5859,12 @@ static void ex_close(exarg_T *eap)
if (eap->addr_count == 0) if (eap->addr_count == 0)
ex_win_close(eap->forceit, curwin, NULL); ex_win_close(eap->forceit, curwin, NULL);
else { else {
for (win = firstwin; win != NULL; win = win->w_next) { FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
winnr++; winnr++;
if (winnr == eap->line2) if (winnr == eap->line2) {
win = wp;
break; break;
}
} }
if (win == NULL) if (win == NULL)
win = lastwin; win = lastwin;
@@ -6074,12 +6076,14 @@ static void ex_hide(exarg_T *eap)
win_close(curwin, FALSE); /* don't free buffer */ win_close(curwin, FALSE); /* don't free buffer */
else { else {
int winnr = 0; int winnr = 0;
win_T *win; win_T *win = NULL;
for (win = firstwin; win != NULL; win = win->w_next) { FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
winnr++; winnr++;
if (winnr == eap->line2) if (winnr == eap->line2) {
win = wp;
break; break;
}
} }
if (win == NULL) if (win == NULL)
win = lastwin; win = lastwin;
@@ -6846,7 +6850,8 @@ static void ex_syncbind(exarg_T *eap)
/* /*
* Set all scrollbind windows to the same topline. * Set all scrollbind windows to the same topline.
*/ */
for (curwin = firstwin; curwin; curwin = curwin->w_next) { FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
curwin = wp;
if (curwin->w_p_scb) { if (curwin->w_p_scb) {
curbuf = curwin->w_buffer; curbuf = curwin->w_buffer;
y = topline - curwin->w_topline; y = topline - curwin->w_topline;

View File

@@ -4733,7 +4733,6 @@ check_timestamps (
int focus /* called for GUI focus event */ int focus /* called for GUI focus event */
) )
{ {
buf_T *buf;
int didit = 0; int didit = 0;
int n; int n;
@@ -4758,7 +4757,7 @@ check_timestamps (
++no_wait_return; ++no_wait_return;
did_check_timestamps = TRUE; did_check_timestamps = TRUE;
already_warned = FALSE; already_warned = FALSE;
for (buf = firstbuf; buf != NULL; ) { FOR_ALL_BUFFERS(buf) {
/* Only check buffers in a window. */ /* Only check buffers in a window. */
if (buf->b_nwindows > 0) { if (buf->b_nwindows > 0) {
bufref_T bufref; bufref_T bufref;
@@ -4773,7 +4772,6 @@ check_timestamps (
continue; continue;
} }
} }
buf = buf->b_next;
} }
--no_wait_return; --no_wait_return;
need_check_timestamps = FALSE; need_check_timestamps = FALSE;

View File

@@ -556,7 +556,6 @@ EXTERN win_T *prevwin INIT(= NULL); /* previous window */
FOR_ALL_TABS(tp) \ FOR_ALL_TABS(tp) \
FOR_ALL_WINDOWS_IN_TAB(wp, tp) FOR_ALL_WINDOWS_IN_TAB(wp, tp)
# define FOR_ALL_WINDOWS(wp) for (wp = firstwin; wp != NULL; wp = wp->w_next)
# define FOR_ALL_WINDOWS_IN_TAB(wp, tp) \ # define FOR_ALL_WINDOWS_IN_TAB(wp, tp) \
for (win_T *wp = ((tp) == curtab) \ for (win_T *wp = ((tp) == curtab) \
? firstwin : (tp)->tp_firstwin; wp != NULL; wp = wp->w_next) ? firstwin : (tp)->tp_firstwin; wp != NULL; wp = wp->w_next)

View File

@@ -2137,7 +2137,8 @@ void do_check_cursorbind(void)
* loop through the cursorbound windows * loop through the cursorbound windows
*/ */
VIsual_select = VIsual_active = 0; VIsual_select = VIsual_active = 0;
for (curwin = firstwin; curwin; curwin = curwin->w_next) { FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
curwin = wp;
curbuf = curwin->w_buffer; curbuf = curwin->w_buffer;
/* skip original window and windows with 'noscrollbind' */ /* skip original window and windows with 'noscrollbind' */
if (curwin != old_curwin && curwin->w_p_crb) { if (curwin != old_curwin && curwin->w_p_crb) {

View File

@@ -3512,7 +3512,8 @@ void check_scrollbind(linenr_T topline_diff, long leftcol_diff)
* loop through the scrollbound windows and scroll accordingly * loop through the scrollbound windows and scroll accordingly
*/ */
VIsual_select = VIsual_active = 0; VIsual_select = VIsual_active = 0;
for (curwin = firstwin; curwin; curwin = curwin->w_next) { FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
curwin = wp;
curbuf = curwin->w_buffer; curbuf = curwin->w_buffer;
/* skip original window and windows with 'noscrollbind' */ /* skip original window and windows with 'noscrollbind' */
if (curwin == old_curwin || !curwin->w_p_scb) { if (curwin == old_curwin || !curwin->w_p_scb) {

View File

@@ -3623,7 +3623,8 @@ set_bool_option (
char_u hash[UNDO_HASH_SIZE]; char_u hash[UNDO_HASH_SIZE];
buf_T *save_curbuf = curbuf; buf_T *save_curbuf = curbuf;
for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next) { FOR_ALL_BUFFERS(bp) {
curbuf = bp;
/* When 'undofile' is set globally: for every buffer, otherwise /* When 'undofile' is set globally: for every buffer, otherwise
* only for the current buffer: Try to read in the undofile, * only for the current buffer: Try to read in the undofile,
* if one exists, the buffer wasn't changed and the buffer was * if one exists, the buffer wasn't changed and the buffer was

View File

@@ -73,7 +73,6 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed)
int above_row; int above_row;
int below_row; int below_row;
int redo_count = 0; int redo_count = 0;
win_T *pvwin;
if (!pum_is_visible) { if (!pum_is_visible) {
// To keep the code simple, we only allow changing the // To keep the code simple, we only allow changing the
@@ -126,8 +125,10 @@ redo:
kind_width = 0; kind_width = 0;
extra_width = 0; extra_width = 0;
FOR_ALL_WINDOWS(pvwin) { win_T *pvwin = NULL;
if (pvwin->w_p_pvw) { FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
if (wp->w_p_pvw) {
pvwin = wp;
break; break;
} }
} }

View File

@@ -339,7 +339,7 @@ static int included_patches[] = {
// 2104, // 2104,
2103, 2103,
// 2102 NA // 2102 NA
// 2101, 2101,
2100, 2100,
2099, 2099,
2098, 2098,

View File

@@ -161,9 +161,13 @@ newwindow:
/* cursor to preview window */ /* cursor to preview window */
case 'P': case 'P':
for (wp = firstwin; wp != NULL; wp = wp->w_next) wp = NULL;
if (wp->w_p_pvw) FOR_ALL_WINDOWS_IN_TAB(wp2, curtab) {
if (wp2->w_p_pvw) {
wp = wp2;
break; break;
}
}
if (wp == NULL) if (wp == NULL)
EMSG(_("E441: There is no preview window")); EMSG(_("E441: There is no preview window"));
else else
@@ -3366,9 +3370,13 @@ void tabpage_move(int nr)
if (curtab == first_tabpage) if (curtab == first_tabpage)
first_tabpage = curtab->tp_next; first_tabpage = curtab->tp_next;
else { else {
for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) tp = NULL;
if (tp->tp_next == curtab) FOR_ALL_TABS(tp2) {
if (tp2->tp_next == curtab) {
tp = tp2;
break; break;
}
}
if (tp == NULL) /* "cannot happen" */ if (tp == NULL) /* "cannot happen" */
return; return;
tp->tp_next = curtab->tp_next; tp->tp_next = curtab->tp_next;
@@ -5753,10 +5761,11 @@ int win_getid(typval_T *argvars)
if (argvars[1].v_type == VAR_UNKNOWN) { if (argvars[1].v_type == VAR_UNKNOWN) {
wp = firstwin; wp = firstwin;
} else { } else {
tabpage_T *tp; tabpage_T *tp = NULL;
int tabnr = get_tv_number(&argvars[1]); int tabnr = get_tv_number(&argvars[1]);
for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) { FOR_ALL_TABS(tp2) {
if (--tabnr == 0) { if (--tabnr == 0) {
tp = tp2;
break; break;
} }
} }
@@ -5833,11 +5842,10 @@ win_T * win_id2wp(typval_T *argvars)
int win_id2win(typval_T *argvars) int win_id2win(typval_T *argvars)
{ {
win_T *wp;
int nr = 1; int nr = 1;
int id = get_tv_number(&argvars[0]); 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) { if (wp->handle == id) {
return nr; return nr;
} }
@@ -5850,12 +5858,9 @@ void win_findbuf(typval_T *argvars, list_T *list)
{ {
int bufnr = get_tv_number(&argvars[0]); int bufnr = get_tv_number(&argvars[0]);
for (tabpage_T *tp = first_tabpage; tp != NULL; tp = tp->tp_next) { FOR_ALL_TAB_WINDOWS(tp, wp) {
for (win_T *wp = tp == curtab ? firstwin : tp->tp_firstwin; if (wp->w_buffer->b_fnum == bufnr) {
wp != NULL; wp = wp->w_next) { list_append_number(list, wp->handle);
if (wp->w_buffer->b_fnum == bufnr) {
list_append_number(list, wp->handle);
}
} }
} }
} }