Problem: Looping over windows, buffers and tab pages is inconsistant.
Solution: Use FOR_ALL_ macros everywhere. (Yegappan Lakshmanan)
* If we can't create one for the current buffer, take another buffer
*/
close_buffer(NULL, curbuf, 0, FALSE);
- for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
+ FOR_ALL_BUFFERS(curbuf)
if (curbuf->b_ml.ml_mfp != NULL)
break;
/*
* If deleting the last (listed) buffer, make it empty.
* The last (listed) buffer cannot be unloaded.
*/
- for (bp = firstbuf; bp != NULL; bp = bp->b_next)
+ FOR_ALL_BUFFERS(bp)
if (bp->b_p_bl && bp != buf)
break;
if (bp == NULL && buf == curbuf)
buf = bp;
if (buf == NULL) /* No loaded buffer, find listed one */
{
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
if (buf->b_p_bl && buf != curbuf)
break;
}
#ifdef FEAT_WINDOWS
win_T *wp;
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
if (wp->w_buffer == buf)
break;
if (wp == NULL)
for (round = 1; round <= 2; ++round)
{
count = 0;
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
{
if (!buf->b_p_bl) /* skip unlisted buffers */
continue;
if (wip->wi_opt.wo_diff)
{
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
/* return FALSE when it's a window in the current tab page, thus
* the buffer was in diff mode here */
if (wip->wi_win == wp)
{
buf_T *bp;
- for (bp = firstbuf; bp != NULL; bp = bp->b_next)
+ FOR_ALL_BUFFERS(bp)
{
if (bp->b_ffname != NULL)
slash_adjust(bp->b_ffname);
#endif
{
/* Check if this buffer already has a window */
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
if (wp->w_buffer == buf)
break;
/* If the buffer already has a window, move it */
#endif
fputs(_("\n# Buffer list:\n"), fp);
- for (buf = firstbuf; buf != NULL ; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
{
if (buf->b_fname == NULL
|| !buf->b_p_bl
{
buf_T *buf; /* buffer we are checking for signs */
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
if (buf->b_signlist != NULL)
buf_delete_signs(buf);
}
int i;
tabpage_T *tp;
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+ FOR_ALL_TABPAGES(tp)
{
i = diff_buf_idx_tp(buf, tp);
if (i != DB_COUNT)
{
/* When there is no window showing a diff for this buffer, remove
* it from the diffs. */
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
if (wp->w_buffer == win->w_buffer && wp->w_p_diff)
break;
if (wp == NULL)
tabpage_T *tp;
int i;
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+ FOR_ALL_TABPAGES(tp)
{
i = diff_buf_idx_tp(buf, tp);
if (i != DB_COUNT)
tabpage_T *tp;
/* Handle all tab pages that use the current buffer in a diff. */
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+ FOR_ALL_TABPAGES(tp)
{
idx = diff_buf_idx_tp(curbuf, tp);
if (idx != DB_COUNT)
win_T *wp;
int n;
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
if (wp->w_p_diff)
{
redraw_win_later(wp, SOME_VALID);
int diffwin = FALSE;
#endif
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
{
if (eap->forceit ? wp->w_p_diff : wp == curwin)
{
/* If "icase" or "iwhite" was added or removed, need to update the diff. */
if (diff_flags != diff_flags_new)
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+ FOR_ALL_TABPAGES(tp)
tp->tp_diff_invalid = TRUE;
diff_flags = diff_flags_new;
int i;
win_T *wp;
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
for (i = 0; i < DB_COUNT; ++i)
if (curtab->tp_diffbuf[i] == wp->w_buffer && i != skip_idx)
foldUpdate(wp, dp->df_lnum[i],
{
tabpage_T *tp;
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+ FOR_ALL_TABPAGES(tp)
if (diff_buf_idx_tp(buf, tp) != DB_COUNT)
return TRUE;
return FALSE;
if (!compl_started)
{
- for (ins_buf = firstbuf; ins_buf != NULL; ins_buf = ins_buf->b_next)
+ FOR_ALL_BUFFERS(ins_buf)
ins_buf->b_scanned = 0;
found_all = FALSE;
ins_buf = curbuf;
abort = abort || set_ref_in_ht(&SCRIPT_VARS(i), copyID, NULL);
/* buffer-local variables */
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
abort = abort || set_ref_in_item(&buf->b_bufvar.di_tv, copyID,
NULL, NULL);
#ifdef FEAT_WINDOWS
/* tabpage-local variables */
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+ FOR_ALL_TABPAGES(tp)
abort = abort || set_ref_in_item(&tp->tp_winvar.di_tv, copyID,
NULL, NULL);
#endif
if (nr == 0)
return curwin;
- for (wp = (tp == NULL || tp == curtab) ? firstwin : tp->tp_firstwin;
- wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS_IN_TAB(tp, wp)
+ {
if (nr >= LOWEST_WIN_ID)
{
if (wp->w_id == nr)
}
else if (--nr <= 0)
break;
+ }
if (nr >= LOWEST_WIN_ID)
return NULL;
return wp;
{
/* No full path name match, try a match with a URL or a "nofile"
* buffer, these don't use the full path. */
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
if (buf->b_fname != NULL
&& (path_with_url(buf->b_fname)
#ifdef FEAT_QUICKFIX
++emsg_off;
buf = get_buf_tv(&argvars[0], TRUE);
#ifdef FEAT_WINDOWS
- for (wp = firstwin; wp; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
{
++winnr;
if (wp->w_buffer == buf)
int n = 0;
buf_T *buf;
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
if (n < buf->b_fnum)
n = buf->b_fnum;
char_u buf[50];
ga_init2(&ga, (int)sizeof(char), 70);
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
{
sprintf((char *)buf, "%dresize %d|", winnr, wp->w_height);
ga_concat(&ga, buf);
&& !autocmd_busy
#endif
&& msg_silent == 0)
- for (buf = firstbuf; buf; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
if (bufIsChanged(buf))
{
#ifdef FEAT_GUI_MSWIN
#endif
/* Change file names to buffer numbers for fmarks. */
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
fmarks_check_names(buf);
return eof;
if (eap->cmdidx == CMD_xall || eap->cmdidx == CMD_wqall)
exiting = TRUE;
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
{
if (bufIsChanged(buf))
{
*/
if (!curwin->w_p_pvw)
{
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
if (wp->w_p_pvw)
break;
if (wp != NULL)
if (cmdmod.tab != 0)
wp = NULL;
else
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
if (wp->w_buffer != NULL && wp->w_buffer->b_help)
break;
if (wp != NULL && wp->w_buffer->b_nwindows > 0)
if (idx == SIGNCMD_UNPLACE && *arg == NUL)
{
/* ":sign unplace {id}": remove placed sign by number */
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
if ((lnum = buf_delsign(buf, id)) != 0)
update_debug_sign(buf, lnum);
return;
if (!(p_aw || p_awa) || !p_write)
return;
- for (buf = firstbuf; buf; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
if (bufIsChanged(buf) && !buf->b_p_ro)
{
#ifdef FEAT_AUTOCMD
int count = 0;
if (flags & CCGD_ALLBUF)
- for (buf2 = firstbuf; buf2 != NULL; buf2 = buf2->b_next)
+ FOR_ALL_BUFFERS(buf2)
if (bufIsChanged(buf2)
&& (buf2->b_ffname != NULL
# ifdef FEAT_BROWSE
* Skip readonly buffers, these need to be confirmed
* individually.
*/
- for (buf2 = firstbuf; buf2 != NULL; buf2 = buf2->b_next)
+ FOR_ALL_BUFFERS(buf2)
{
if (bufIsChanged(buf2)
&& (buf2->b_ffname != NULL
/*
* mark all buffers as unchanged
*/
- for (buf2 = firstbuf; buf2 != NULL; buf2 = buf2->b_next)
+ FOR_ALL_BUFFERS(buf2)
unchanged(buf2, TRUE);
}
}
win_T *wp;
#endif
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
++bufcount;
if (bufcount == 0)
add_bufnum(bufnrs, &bufnum, wp->w_buffer->b_fnum);
/* buf in other tab */
- 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)
add_bufnum(bufnrs, &bufnum, wp->w_buffer->b_fnum);
#endif
/* any other buf */
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
add_bufnum(bufnrs, &bufnum, buf->b_fnum);
for (i = 0; i < bufnum; ++i)
if (next_fnum < 0 || next_fnum > eap->line2)
break;
/* Check if the buffer still exists. */
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
if (buf->b_fnum == next_fnum)
break;
if (buf == NULL)
win_T *wp;
int nr = 0;
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
{
++nr;
if (wp == win)
tabpage_T *tp;
int nr = 0;
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+ FOR_ALL_TABPAGES(tp)
{
++nr;
if (tp == tab)
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(win)
{
winnr++;
if (winnr == eap->line2)
{
win_T *win;
- for (win = firstwin; win != NULL; win = win->w_next)
+ FOR_ALL_WINDOWS(win)
if (win->w_p_pvw)
{
ex_win_close(eap->forceit, win, NULL);
* up the lists. */
for (done = 0; done < 1000; ++done)
{
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+ FOR_ALL_TABPAGES(tp)
if (tp->tp_topframe != topframe)
{
tabpage_close_other(tp, eap->forceit);
break;
}
+#ifdef FEAT_AUTOCMD
+ apply_autocmds(EVENT_TABCLOSED, NULL, NULL, FALSE, curbuf);
+#endif
+
redraw_tabline = TRUE;
if (h != tabline_height())
shell_new_rows();
int winnr = 0;
win_T *win;
- for (win = firstwin; win != NULL; win = win->w_next)
+ FOR_ALL_WINDOWS(win)
{
winnr++;
if (winnr == eap->line2)
if (curwin->w_p_scb)
{
topline = curwin->w_topline;
- for (wp = firstwin; wp; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
{
if (wp->w_p_scb && wp->w_buffer)
{
/*
* Set all scrollbind windows to the same topline.
*/
- for (curwin = firstwin; curwin; curwin = curwin->w_next)
+ FOR_ALL_WINDOWS(curwin)
{
if (curwin->w_p_scb)
{
return FAIL;
/* Now put the other buffers into the buffer list */
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
{
if (!(only_save_windows && buf->b_nwindows == 0)
&& !(buf->b_help && !(ssop_flags & SSOP_HELP))
char_u *p;
mch_dirname(dirname, MAXPATHL);
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
{
if (buf->b_fname != NULL
#ifdef FEAT_QUICKFIX
++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)
continue;
}
}
- buf = buf->b_next;
}
--no_wait_return;
need_check_timestamps = FALSE;
* gives problems when the autocommands make changes to the list of
* buffers or windows...
*/
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
{
if (buf->b_ml.ml_mfp != NULL)
{
win = curwin;
else
#ifdef FEAT_WINDOWS
- for (win = firstwin; win != NULL; win = win->w_next)
+ FOR_ALL_WINDOWS(win)
if (win->w_buffer == buf)
break;
#else
EXTERN win_T *prevwin INIT(= NULL); /* previous window */
# define W_NEXT(wp) ((wp)->w_next)
# define FOR_ALL_WINDOWS(wp) for (wp = firstwin; wp != NULL; wp = wp->w_next)
+# define FOR_ALL_TABPAGES(tp) for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+# define FOR_ALL_WINDOWS_IN_TAB(tp, wp) \
+ for ((wp) = ((tp) == NULL || (tp) == curtab) \
+ ? firstwin : (tp)->tp_firstwin; (wp); (wp) = (wp)->w_next)
/*
* When using this macro "break" only breaks out of the inner loop. Use "goto"
* to break out of the tabpage loop.
# define lastwin curwin
# define W_NEXT(wp) NULL
# define FOR_ALL_WINDOWS(wp) wp = curwin;
+# define FOR_ALL_TABPAGES(tp) for (;FALSE;)
+# define FOR_ALL_WINDOWS_IN_TAB(tp, wp) wp = curwin;
# define FOR_ALL_TAB_WINDOWS(tp, wp) wp = curwin;
#endif
EXTERN buf_T *lastbuf INIT(= NULL); /* last buffer */
EXTERN buf_T *curbuf INIT(= NULL); /* currently active buffer */
+#define FOR_ALL_BUFFERS(buf) for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+
/* Flag that is set when switching off 'swapfile'. It means that all blocks
* are to be loaded into memory. Shouldn't be global... */
EXTERN int mf_dont_release INIT(= FALSE); /* don't release blocks */
{
do_check_scrollbind(TRUE);
/* need to update the window right here */
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
if (wp->w_redr_type > 0)
updateWindow(wp);
setcursor();
/* avoid that moving components around generates events */
++hold_gui_events;
- for (wp = firstwin; wp != NULL; wp = W_NEXT(wp))
+ FOR_ALL_WINDOWS(wp)
{
if (wp->w_buffer == NULL) /* just in case */
continue;
if (error)
return error;
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
if (buf->b_ml.ml_mfp != NULL
&& SearchData.theFile.parID == buf->b_FSSpec.parID
&& SearchData.theFile.name[0] == buf->b_FSSpec.name[0]
#endif
numFiles = 0;
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
if (buf->b_ml.ml_mfp != NULL)
{
/* Add this file to the list */
if (error)
return error;
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
if (buf->b_ml.ml_mfp != NULL)
if (GetTextData.theFile.parID == buf->b_FSSpec.parID)
{
tabpage_T *tp;
int numTabs = 0;
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+ FOR_ALL_TABPAGES(tp)
++numTabs;
return numTabs;
}
if (lua_isnumber(L, 1)) /* by number? */
{
int n = lua_tointeger(L, 1);
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
if (buf->b_fnum == n) break;
}
else { /* by name */
size_t l;
const char *s = lua_tolstring(L, 1, &l);
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
{
if (buf->b_ffname == NULL || buf->b_sfname == NULL)
{
#ifdef FEAT_WINDOWS
win_T *w;
- for (w = firstwin; w != NULL; w = w->w_next)
+ FOR_ALL_WINDOWS(w)
#endif
++n;
return scheme_make_integer(n);
fnum = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0));
- for (buf = firstbuf; buf; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
if (buf->b_fnum == fnum)
return buffer_new(buf);
fname = GUARANTEED_STRING_ARG(prim->name, 0);
buffer = scheme_false;
- for (buf = firstbuf; buf; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
{
if (buf->b_ffname == NULL || buf->b_sfname == NULL)
/* empty string */
buf_T *b;
int n = 0;
- for (b = firstbuf; b; b = b->b_next) ++n;
+ FOR_ALL_BUFFERS(b) ++n;
return scheme_make_integer(n);
}
if (GIMME == G_SCALAR)
{
i = 0;
- for (vimbuf = firstbuf; vimbuf; vimbuf = vimbuf->b_next)
+ FOR_ALL_BUFFERS(vimbuf)
++i;
XPUSHs(sv_2mortal(newSViv(i)));
}
else
{
- for (vimbuf = firstbuf; vimbuf; vimbuf = vimbuf->b_next)
+ FOR_ALL_BUFFERS(vimbuf)
XPUSHs(newBUFrv(newSV(0), vimbuf));
}
}
XPUSHs(sv_2mortal(newSViv(win_count())));
else
{
- for (vimwin = firstwin; vimwin != NULL; vimwin = W_NEXT(vimwin))
+ FOR_ALL_WINDOWS(vimwin)
XPUSHs(newWINrv(newSV(0), vimwin));
}
}
buf_T *b;
int n = 0;
- for (b = firstbuf; b != NULL; b = b->b_next)
+ FOR_ALL_BUFFERS(b)
{
/* Deleted buffers should not be counted
* SegPhault - 01/07/05 */
buf_T *b;
int n = NUM2INT(num);
- for (b = firstbuf; b != NULL; b = b->b_next)
+ FOR_ALL_BUFFERS(b)
{
/* Deleted buffers should not be counted
* SegPhault - 01/07/05 */
win_T *w;
int n = 0;
- for (w = firstwin; w != NULL; w = w->w_next)
+ FOR_ALL_WINDOWS(w)
n++;
return INT2NUM(n);
#else
Tcl_WrongNumArgs(interp, 1, objv, "bufNumber");
return TCL_ERROR;
}
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
{
if (buf->b_fnum == n)
{
err = TCL_ERROR;
break;
}
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
{
name = tclgetbuffer(interp, buf);
if (name == NULL)
win_T *wp;
/* set options in each window for "vimdiff". */
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
diff_win_options(wp, TRUE);
}
#endif
for (tp = first_tabpage; tp != NULL; tp = next_tp)
{
next_tp = tp->tp_next;
- for (wp = (tp == curtab)
- ? firstwin : tp->tp_firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS_IN_TAB(tp, wp)
{
if (wp->w_buffer == NULL)
/* Autocmd must have close the buffer already, skip. */
# endif
/* Trigger BufUnload for buffers that are loaded */
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
if (buf->b_ml.ml_mfp != NULL)
{
bufref_T bufref;
#endif
fputs(_("\n# History of marks within files (newest to oldest):\n"), fp_out);
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
{
/*
* Only write something if buffer has been loaded and at least one
else /* fp_out != NULL */
{
/* This is slow if there are many buffers!! */
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
if (buf->b_ffname != NULL)
{
home_replace(NULL, buf->b_ffname, name_buf, LSIZE, TRUE);
if (mfp->mf_fd < 0 && need_release && p_uc)
{
/* find for which buffer this memfile is */
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
if (buf->b_ml.ml_mfp == mfp)
break;
if (buf != NULL && buf->b_may_swap)
bhdr_T *hp;
int retval = FALSE;
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
{
mfp = buf->b_ml.ml_mfp;
if (mfp != NULL)
{
buf_T *buf;
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
if (!buf->b_p_ro || buf->b_changed)
ml_open_file(buf);
}
{
buf_T *buf;
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
ml_close(buf, del_file && ((buf->b_flags & BF_PRESERVED) == 0
|| vim_strchr(p_cpo, CPO_PRESERVE) == NULL));
#ifdef FEAT_SPELL
{
buf_T *buf;
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
if (!bufIsChanged(buf))
ml_close(buf, TRUE); /* close all not-modified buffers */
}
buf_T *buf;
stat_T st;
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
{
if (buf->b_ml.ml_mfp == NULL || buf->b_ml.ml_mfp->mf_fname == NULL)
continue; /* no file */
win_T *wp;
linenr_T wlnum;
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
if (wp->w_p_diff && wp != curwin)
{
redraw_win_later(wp, VALID);
win_T *wp;
linenr_T wlnum;
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
if (wp->w_p_diff && wp != curwin)
{
redraw_win_later(wp, VALID);
{
win_T *wp;
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
if (wp->w_buffer == buf && wp->w_status_height)
{
wp->w_redr_status = TRUE;
ml_close_notmod(); /* close all not-modified buffers */
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
{
if (buf->b_ml.ml_mfp != NULL && buf->b_ml.ml_mfp->mf_fname != NULL)
{
* loop through the cursorbound windows
*/
VIsual_select = VIsual_active = 0;
- for (curwin = firstwin; curwin; curwin = curwin->w_next)
+ FOR_ALL_WINDOWS(curwin)
{
curbuf = curwin->w_buffer;
/* skip original window and windows with 'noscrollbind' */
{
buf_T *buf;
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
buf->b_has_sign_column = FALSE;
/* The IDE is breaking the connection. */
int n;
n = 0;
- for (bufp = firstbuf; bufp != NULL; bufp = bufp->b_next)
+ FOR_ALL_BUFFERS(bufp)
if (bufp->b_changed)
++n;
return n;
* loop through the scrollbound windows and scroll accordingly
*/
VIsual_select = VIsual_active = 0;
- for (curwin = firstwin; curwin; curwin = curwin->w_next)
+ FOR_ALL_WINDOWS(curwin)
{
curbuf = curwin->w_buffer;
/* skip original window and windows with 'noscrollbind' */
{
buf_T *buf;
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
if (buf != curbuf && *buf->b_p_cm == NUL)
ml_set_crypt_key(buf, buf->b_p_key, oldval);
}
char_u hash[UNDO_HASH_SIZE];
buf_T *save_curbuf = curbuf;
- for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
+ FOR_ALL_BUFFERS(curbuf)
{
/* When 'undofile' is set globally: for every buffer, otherwise
* only for the current buffer: Try to read in the undofile,
{
win_T *win;
- for (win = firstwin; win != NULL; win = win->w_next)
+ FOR_ALL_WINDOWS(win)
if (win->w_p_pvw && win != curwin)
{
curwin->w_p_pvw = FALSE;
if (!old_p_paste)
{
/* save options for each buffer */
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
{
buf->b_p_tw_nopaste = buf->b_p_tw;
buf->b_p_wm_nopaste = buf->b_p_wm;
* already on.
*/
/* set options for each buffer */
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
{
buf->b_p_tw = 0; /* textwidth is 0 */
buf->b_p_wm = 0; /* wrapmargin is 0 */
else if (old_p_paste)
{
/* restore options for each buffer */
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
{
buf->b_p_tw = buf->b_p_tw_nopaste;
buf->b_p_wm = buf->b_p_wm_nopaste;
if (cmdmod.tab != 0)
wp = NULL;
else
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
if (wp->w_buffer != NULL && wp->w_buffer->b_help)
break;
if (wp != NULL && wp->w_buffer->b_nwindows > 0)
#ifdef FEAT_WINDOWS
/* Reset b_mod_set flags. Going through all windows is probably faster
* than going through all buffers (there could be many buffers). */
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
wp->w_buffer->b_mod_set = FALSE;
#else
curbuf->b_mod_set = FALSE;
update_prepare();
# ifdef FEAT_WINDOWS
- for (wp = firstwin; wp; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
{
if (wp->w_redr_type != 0)
win_update(wp);
{
win_T *wp;
- for (wp = firstwin; wp; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
if (wp->w_status_height)
{
wp->w_redr_status = TRUE;
{
win_T *wp;
- for (wp = firstwin; wp; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
if (wp->w_status_height != 0 && wp->w_buffer == curbuf)
{
wp->w_redr_status = TRUE;
{
win_T *wp;
- for (wp = firstwin; wp; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
if (wp->w_redr_status)
win_redr_status(wp);
if (redraw_tabline)
else
#endif
{
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+ FOR_ALL_TABPAGES(tp)
++tabcount;
tabwidth = (Columns - 1 + tabcount / 2) / tabcount;
buf_T *buf;
/* Go through all buffers and handle 'spelllang'. <VN> */
- for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+ FOR_ALL_BUFFERS(buf)
ga_clear(&buf->b_s.b_langp);
while (first_lang != NULL)
spell_free_all();
/* Go through all buffers and handle 'spelllang'. */
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
{
/* Only load the wordlists when 'spelllang' is set and there is a
* window for this buffer in which 'spell' is set. */
* loaded.
*/
set_bufref(&old_curbuf, curbuf);
- for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
+ FOR_ALL_BUFFERS(curbuf)
{
if (curbuf->b_ml.ml_mfp != NULL)
apply_autocmds(EVENT_TERMCHANGED, NULL, NULL, FALSE,
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 2101,
/**/
2100,
/**/
/* 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)
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;
win_T *wp;
int count = 0;
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp)
++count;
return count;
}
{
tabpage_T *tp;
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+ FOR_ALL_TABPAGES(tp)
if (tp == tpc)
return TRUE;
return FALSE;
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" */
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;
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;
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)
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)
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;
}
/* 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;
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;
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);
{
/* 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;
#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)
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
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)
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);
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)
{
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;
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);
}
{
win_T *wp = NULL; /* window filename is in */
- for (wp = firstwin; wp != NULL; wp = W_NEXT(wp))
+ FOR_ALL_WINDOWS(wp)
if (buf == wp->w_buffer)
break;
return wp;