patch 7.4.2101
Problem: Looping over windows, buffers and tab pages is inconsistant.
Solution: Use FOR_ALL_ macros everywhere. (Yegappan Lakshmanan)
diff --git a/src/window.c b/src/window.c
index 4fbe6ca..925a1471 100644
--- a/src/window.c
+++ b/src/window.c
@@ -209,7 +209,7 @@
/* cursor to preview window */
case 'P':
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
if (wp->w_p_pvw)
break;
if (wp == NULL)
@@ -1367,7 +1367,7 @@
if (win == NULL)
return FALSE;
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
if (wp == win)
return TRUE;
return FALSE;
@@ -1382,7 +1382,7 @@
win_T *wp;
int count = 0;
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
++count;
return count;
}
@@ -3712,7 +3712,7 @@
{
tabpage_T *tp;
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+ FOR_ALL_TABPAGES(tp)
if (tp == tpc)
return TRUE;
return FALSE;
@@ -4012,7 +4012,7 @@
first_tabpage = curtab->tp_next;
else
{
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+ FOR_ALL_TABPAGES(tp)
if (tp->tp_next == curtab)
break;
if (tp == NULL) /* "cannot happen" */
@@ -4091,7 +4091,7 @@
win_T *wp;
# ifdef FEAT_WINDOWS
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
if (--winnr == 0)
break;
return wp;
@@ -4112,9 +4112,7 @@
win_T *wp;
tabpage_T *tp;
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
- for (wp = (tp == curtab ? firstwin : tp->tp_firstwin);
- wp != NULL; wp = wp->w_next)
+ FOR_ALL_TAB_WINDOWS(tp, wp)
if (wp == win)
return tp;
return NULL;
@@ -4404,7 +4402,7 @@
wp = curwin;
# ifdef FEAT_WINDOWS
else
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
if (wp->w_buffer == buf)
break;
if (wp != NULL)
@@ -4428,7 +4426,7 @@
if (wp != NULL)
return wp;
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+ FOR_ALL_TABPAGES(tp)
if (tp != curtab)
{
for (wp = tp->tp_firstwin; wp != NULL; wp = wp->w_next)
@@ -4607,7 +4605,7 @@
if (prevwin == wp)
prevwin = NULL;
- for (ttp = first_tabpage; ttp != NULL; ttp = ttp->tp_next)
+ FOR_ALL_TABPAGES(ttp)
if (ttp->tp_prevwin == wp)
ttp->tp_prevwin = NULL;
}
@@ -4620,7 +4618,7 @@
/* Remove the window from the b_wininfo lists, it may happen that the
* freed memory is re-used for another window. */
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next)
if (wip->wi_win == wp)
wip->wi_win = NULL;
@@ -4863,7 +4861,7 @@
ga_init2(gap, (int)sizeof(int), 1);
if (ga_grow(gap, win_count() * 2) == OK)
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
{
((int *)gap->ga_data)[gap->ga_len++] =
wp->w_width + wp->w_vsep_width;
@@ -4888,7 +4886,7 @@
for (j = 0; j < 2; ++j)
{
i = 0;
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
{
frame_setwidth(wp->w_frame, ((int *)gap->ga_data)[i++]);
win_setheight_win(((int *)gap->ga_data)[i++], wp);
@@ -5384,7 +5382,7 @@
{
/* TODO: handle vertical splits */
room = -p_wh;
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
room += wp->w_height - p_wmh;
if (room >= 0)
break;
@@ -6344,7 +6342,7 @@
#ifdef FEAT_WINDOWS
total = 0;
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+ FOR_ALL_TABPAGES(tp)
{
n = frame_minheight(tp->tp_topframe, NULL);
if (total < n)
@@ -6374,7 +6372,7 @@
if (first_tabpage->tp_next != NULL)
return FALSE;
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
if (wp->w_buffer != NULL
&& (!((wp->w_buffer->b_help && !curbuf->b_help)
# ifdef FEAT_QUICKFIX
@@ -7091,7 +7089,7 @@
tabpage_T *tp;
int tabnr = get_tv_number(&argvars[1]);
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+ FOR_ALL_TABPAGES(tp)
if (--tabnr == 0)
break;
if (tp == NULL)
@@ -7112,9 +7110,7 @@
tabpage_T *tp;
int id = get_tv_number(&argvars[0]);
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
- for (wp = tp == curtab ? firstwin : tp->tp_firstwin;
- wp != NULL; wp = wp->w_next)
+ FOR_ALL_TAB_WINDOWS(tp, wp)
if (wp->w_id == id)
{
goto_tabpage_win(tp, wp);
@@ -7132,10 +7128,9 @@
int tabnr = 1;
int id = get_tv_number(&argvars[0]);
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+ FOR_ALL_TABPAGES(tp)
{
- for (wp = tp == curtab ? firstwin : tp->tp_firstwin;
- wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS_IN_TAB(tp, wp)
{
if (wp->w_id == id)
{
@@ -7159,7 +7154,7 @@
int nr = 1;
int id = get_tv_number(&argvars[0]);
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
{
if (wp->w_id == id)
return nr;
@@ -7175,9 +7170,7 @@
tabpage_T *tp;
int bufnr = get_tv_number(&argvars[0]);
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
- for (wp = tp == curtab ? firstwin : tp->tp_firstwin;
- wp != NULL; wp = wp->w_next)
+ FOR_ALL_TAB_WINDOWS(tp, wp)
if (wp->w_buffer->b_fnum == bufnr)
list_append_number(list, wp->w_id);
}