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
No known key found for this signature in database
GPG Key ID: DFE691AE331BA3DB
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)
wp = NULL;
else
for (wp = firstwin; wp != NULL; wp = wp->w_next)
if (wp->w_buffer != NULL && wp->w_buffer->b_help)
else {
wp = NULL;
FOR_ALL_WINDOWS_IN_TAB(wp2, curtab) {
if (wp2->w_buffer != NULL && wp2->w_buffer->b_help) {
wp = wp2;
break;
}
}
}
if (wp != NULL && wp->w_buffer->b_nwindows > 0)
win_enter(wp, true);
else {

View File

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

View File

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

View File

@ -556,7 +556,6 @@ EXTERN win_T *prevwin INIT(= NULL); /* previous window */
FOR_ALL_TABS(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) \
for (win_T *wp = ((tp) == curtab) \
? 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
*/
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;
/* skip original window and windows with 'noscrollbind' */
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
*/
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;
/* skip original window and windows with 'noscrollbind' */
if (curwin == old_curwin || !curwin->w_p_scb) {

View File

@ -3623,7 +3623,8 @@ set_bool_option (
char_u hash[UNDO_HASH_SIZE];
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
* only for the current buffer: Try to read in the undofile,
* 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 below_row;
int redo_count = 0;
win_T *pvwin;
if (!pum_is_visible) {
// To keep the code simple, we only allow changing the
@ -126,8 +125,10 @@ redo:
kind_width = 0;
extra_width = 0;
FOR_ALL_WINDOWS(pvwin) {
if (pvwin->w_p_pvw) {
win_T *pvwin = NULL;
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
if (wp->w_p_pvw) {
pvwin = wp;
break;
}
}

View File

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

View File

@ -161,9 +161,13 @@ 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)
EMSG(_("E441: There is no preview window"));
else
@ -3366,9 +3370,13 @@ void tabpage_move(int nr)
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)
tp = NULL;
FOR_ALL_TABS(tp2) {
if (tp2->tp_next == curtab) {
tp = tp2;
break;
}
}
if (tp == NULL) /* "cannot happen" */
return;
tp->tp_next = curtab->tp_next;
@ -5753,10 +5761,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 +5842,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 +5858,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);
}
}
}