aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWayne Rowcliffe <war1025@gmail.com>2014-08-20 19:39:05 -0500
committerWayne Rowcliffe <war1025@gmail.com>2014-09-08 17:27:41 -0500
commitac0b9714edbb7697b8324f922024401baea8953b (patch)
tree85449173705a443081b1189a9d1087df74030703
parentfe99930c46c096b9be277d3201b3ea9b5bf2f659 (diff)
downloadrneovim-ac0b9714edbb7697b8324f922024401baea8953b.tar.gz
rneovim-ac0b9714edbb7697b8324f922024401baea8953b.tar.bz2
rneovim-ac0b9714edbb7697b8324f922024401baea8953b.zip
Additional FOR_ALL_WINDOWS usage
-rw-r--r--src/nvim/buffer.c48
-rw-r--r--src/nvim/diff.c20
-rw-r--r--src/nvim/eval.c20
-rw-r--r--src/nvim/ex_cmds.c16
-rw-r--r--src/nvim/ex_cmds2.c7
-rw-r--r--src/nvim/ex_docmd.c14
-rw-r--r--src/nvim/fileio.c13
-rw-r--r--src/nvim/main.c5
-rw-r--r--src/nvim/misc1.c19
-rw-r--r--src/nvim/option.c4
-rw-r--r--src/nvim/quickfix.c14
-rw-r--r--src/nvim/screen.c17
-rw-r--r--src/nvim/spell.c4
-rw-r--r--src/nvim/window.c45
14 files changed, 123 insertions, 123 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 3c7fd777bd..7afa663fe3 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -1763,13 +1763,16 @@ buflist_findpat (
if (curtab_only) {
/* Ignore the match if the buffer is not open in
* the current tab. */
- win_T *wp;
-
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
- if (wp->w_buffer == buf)
+ bool found_window = false;
+ FOR_ALL_WINDOWS(wp) {
+ if (wp->w_buffer == buf) {
+ found_window = true;
break;
- if (wp == NULL)
+ }
+ }
+ if (!found_window) {
continue;
+ }
}
if (match >= 0) { /* already found a match */
match = -2;
@@ -2020,22 +2023,22 @@ static void buflist_setfpos(buf_T *buf, win_T *win, linenr_T lnum, colnr_T col,
/*
- * Return TRUE when "wip" has 'diff' set and the diff is only for another tab
+ * Return true when "wip" has 'diff' set and the diff is only for another tab
* page. That's because a diff is local to a tab page.
*/
-static int wininfo_other_tab_diff(wininfo_T *wip)
+static bool wininfo_other_tab_diff(wininfo_T *wip)
{
- win_T *wp;
-
if (wip->wi_opt.wo_diff) {
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
- /* return FALSE when it's a window in the current tab page, thus
+ 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)
- return FALSE;
- return TRUE;
+ if (wip->wi_win == wp) {
+ return false;
+ }
+ }
+ return true;
}
- return FALSE;
+ return false;
}
/*
@@ -3601,7 +3604,6 @@ do_arg_all (
)
{
int i;
- win_T *wp, *wpnext;
char_u *opened; /* Array of weight for which args are open:
* 0: not opened
* 1: opened in other tab
@@ -3651,8 +3653,9 @@ do_arg_all (
if (had_tab > 0)
goto_tabpage_tp(first_tabpage, TRUE, TRUE);
for (;; ) {
+ win_T *wpnext = NULL;
tpnext = curtab->tp_next;
- for (wp = firstwin; wp != NULL; wp = wpnext) {
+ for (win_T *wp = firstwin; wp != NULL; wp = wpnext) {
wpnext = wp->w_next;
buf = wp->w_buffer;
if (buf->b_ffname == NULL
@@ -3762,13 +3765,14 @@ do_arg_all (
if (opened[i] > 0) {
/* Move the already present window to below the current window */
if (curwin->w_arg_idx != i) {
- for (wpnext = firstwin; wpnext != NULL; wpnext = wpnext->w_next) {
- if (wpnext->w_arg_idx == i) {
+ FOR_ALL_WINDOWS(wp) {
+ if (wp->w_arg_idx == i) {
if (keep_tabs) {
- new_curwin = wpnext;
+ new_curwin = wp;
new_curtab = curtab;
- } else
- win_move_after(wpnext, curwin);
+ } else {
+ win_move_after(wp, curwin);
+ }
break;
}
}
diff --git a/src/nvim/diff.c b/src/nvim/diff.c
index 73b5731ad0..8f540fbe09 100644
--- a/src/nvim/diff.c
+++ b/src/nvim/diff.c
@@ -87,14 +87,14 @@ void diff_buf_adjust(win_T *win)
if (!win->w_p_diff) {
// When there is no window showing a diff for this buffer, remove
// it from the diffs.
- win_T *wp;
- for (wp = firstwin; wp != NULL; wp = wp->w_next) {
+ bool found_win = false;
+ FOR_ALL_WINDOWS(wp) {
if ((wp->w_buffer == win->w_buffer) && wp->w_p_diff) {
- break;
+ found_win = true;
}
}
- if (wp == NULL) {
+ if (!found_win) {
int i = diff_buf_idx(win->w_buffer);
if (i != DB_COUNT) {
curtab->tp_diffbuf[i] = NULL;
@@ -581,8 +581,7 @@ static int diff_check_sanity(tabpage_T *tp, diff_T *dp)
/// @param dofold Also recompute the folds
static void diff_redraw(int dofold)
{
- win_T *wp;
- for (wp = firstwin; wp != NULL; wp = wp->w_next) {
+ FOR_ALL_WINDOWS(wp) {
if (wp->w_p_diff) {
redraw_win_later(wp, SOME_VALID);
if (dofold && foldmethodIsDiff(wp)) {
@@ -1111,8 +1110,7 @@ void ex_diffoff(exarg_T *eap)
win_T *old_curwin = curwin;
int diffwin = FALSE;
- win_T *wp;
- for (wp = firstwin; wp != NULL; wp = wp->w_next) {
+ FOR_ALL_WINDOWS(wp) {
if (eap->forceit ? wp->w_p_diff : (wp == curwin)) {
// Set 'diff', 'scrollbind' off and 'wrap' on. If option values
// were saved in diff_win_options() restore them.
@@ -2364,10 +2362,8 @@ void ex_diffgetput(exarg_T *eap)
/// @param skip_idx
static void diff_fold_update(diff_T *dp, int skip_idx)
{
- win_T *wp;
- for (wp = firstwin; wp != NULL; wp = wp->w_next) {
- int i;
- for (i = 0; i < DB_COUNT; ++i) {
+ FOR_ALL_WINDOWS(wp) {
+ for (int i = 0; i < DB_COUNT; ++i) {
if ((curtab->tp_diffbuf[i] == wp->w_buffer) && (i != skip_idx)) {
foldUpdate(wp, dp->df_lnum[i], dp->df_lnum[i] + dp->df_count[i]);
}
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index a61f082e59..8549991eda 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -7361,19 +7361,20 @@ static void f_bufnr(typval_T *argvars, typval_T *rettv)
*/
static void f_bufwinnr(typval_T *argvars, typval_T *rettv)
{
- win_T *wp;
- int winnr = 0;
- buf_T *buf;
-
(void)get_tv_number(&argvars[0]); /* issue errmsg if type error */
++emsg_off;
- buf = get_buf_tv(&argvars[0], TRUE);
- for (wp = firstwin; wp; wp = wp->w_next) {
+
+ buf_T *buf = get_buf_tv(&argvars[0], TRUE);
+ int winnr = 0;
+ bool found_buf = false;
+ FOR_ALL_WINDOWS(wp) {
++winnr;
- if (wp->w_buffer == buf)
+ if (wp->w_buffer == buf) {
+ found_buf = true;
break;
+ }
}
- rettv->vval.v_number = (wp != NULL ? winnr : -1);
+ rettv->vval.v_number = (found_buf ? winnr : -1);
--emsg_off;
}
@@ -14750,13 +14751,12 @@ static void f_winnr(typval_T *argvars, typval_T *rettv)
*/
static void f_winrestcmd(typval_T *argvars, typval_T *rettv)
{
- win_T *wp;
int winnr = 1;
garray_T ga;
char_u buf[50];
ga_init(&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);
sprintf((char *)buf, "vert %dresize %d|", winnr, wp->w_width);
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index 18216f6924..b72d1941ec 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -4610,19 +4610,19 @@ prepare_tagpreview (
bool undo_sync /* sync undo when leaving the window */
)
{
- win_T *wp;
-
-
/*
* If there is already a preview window open, use that one.
*/
if (!curwin->w_p_pvw) {
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
- if (wp->w_p_pvw)
+ bool found_win = false;
+ FOR_ALL_WINDOWS(wp) {
+ if (wp->w_p_pvw) {
+ win_enter(wp, undo_sync);
+ found_win = true;
break;
- if (wp != NULL)
- win_enter(wp, undo_sync);
- else {
+ }
+ }
+ if (!found_win) {
/*
* There is no preview window open yet. Create one.
*/
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c
index fdf225c073..f1524ffce9 100644
--- a/src/nvim/ex_cmds2.c
+++ b/src/nvim/ex_cmds2.c
@@ -1228,7 +1228,7 @@ check_changed_any (
/* buf in other tab */
for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) {
if (tp != curtab) {
- for (wint_T *wp = tp->tp_firstwin; wp != NULL; wp = wp->w_next) {
+ for (win_T *wp = tp->tp_firstwin; wp != NULL; wp = wp->w_next) {
add_bufnum(bufnrs, &bufnum, wp->w_buffer->b_fnum);
}
}
@@ -1282,8 +1282,8 @@ check_changed_any (
}
/* Try to find a window that contains the buffer. */
- if (buf != curbuf)
- wint_T *wp;
+ if (buf != curbuf) {
+ win_T *wp;
FOR_ALL_TAB_WINDOWS(tp, wp) {
if (wp->w_buffer == buf) {
goto_tabpage_win(tp, wp);
@@ -1294,6 +1294,7 @@ check_changed_any (
goto buf_found;
}
}
+ }
buf_found:
/* Open the changed buffer in the current window. */
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 2dc5ad436d..dacd0f9e31 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -5188,13 +5188,12 @@ static void ex_close(exarg_T *eap)
*/
static void ex_pclose(exarg_T *eap)
{
- 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);
break;
}
+ }
}
/*
@@ -6119,7 +6118,6 @@ static void ex_swapname(exarg_T *eap)
*/
static void ex_syncbind(exarg_T *eap)
{
- win_T *wp;
win_T *save_curwin = curwin;
buf_T *save_curbuf = curbuf;
long topline;
@@ -6133,15 +6131,17 @@ static void ex_syncbind(exarg_T *eap)
*/
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) {
y = wp->w_buffer->b_ml.ml_line_count - p_so;
- if (topline > y)
+ if (topline > y) {
topline = y;
+ }
}
}
- if (topline < 1)
+ if (topline < 1) {
topline = 1;
+ }
} else {
topline = 1;
}
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index 0a05b2a4db..97daa035f8 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -6177,12 +6177,17 @@ aucmd_prepbuf (
int save_acd;
/* Find a window that is for the new buffer */
- if (buf == curbuf) /* be quick when buf is curbuf */
+ if (buf == curbuf) { /* be quick when buf is curbuf */
win = curwin;
- else
- for (win = firstwin; win != NULL; win = win->w_next)
- if (win->w_buffer == buf)
+ } else {
+ win = NULL;
+ FOR_ALL_WINDOWS(wp) {
+ if (wp->w_buffer == buf) {
+ win = wp;
break;
+ }
+ }
+ }
/* Allocate "aucmd_win" when needed. If this fails (out of memory) fall
* back to using the current window. */
diff --git a/src/nvim/main.c b/src/nvim/main.c
index 9ab46b1ce2..ebd9f7f3ff 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -471,11 +471,10 @@ int main(int argc, char **argv)
edit_buffers(&params);
if (params.diff_mode) {
- 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);
+ }
}
/*
diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c
index 8669977ea1..f670098896 100644
--- a/src/nvim/misc1.c
+++ b/src/nvim/misc1.c
@@ -1877,16 +1877,16 @@ void changed_bytes(linenr_T lnum, colnr_T col)
/* Diff highlighting in other diff windows may need to be updated too. */
if (curwin->w_p_diff) {
- 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);
wlnum = diff_lnum_win(lnum, wp);
if (wlnum > 0)
changedOneline(wp->w_buffer, wlnum);
}
+ }
}
}
@@ -1973,17 +1973,18 @@ changed_lines (
/* When the number of lines doesn't change then mark_adjust() isn't
* called and other diff buffers still need to be marked for
* displaying. */
- 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);
wlnum = diff_lnum_win(lnum, wp);
- if (wlnum > 0)
+ if (wlnum > 0) {
changed_lines_buf(wp->w_buffer, wlnum,
lnume - lnum + wlnum, 0L);
+ }
}
+ }
}
changed_common(lnum, col, lnume, xtra);
@@ -2214,14 +2215,14 @@ unchanged (
*/
void check_status(buf_T *buf)
{
- 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;
- if (must_redraw < VALID)
+ if (must_redraw < VALID) {
must_redraw = VALID;
+ }
}
+ }
}
/*
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 273e4cf0c0..b9becebbf4 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -5075,9 +5075,7 @@ set_bool_option (
/* There can be only one window with 'previewwindow' set. */
else if ((int *)varp == &curwin->w_p_pvw) {
if (curwin->w_p_pvw) {
- 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;
return (char_u *)N_("E590: A preview window already exists");
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c
index bbd837fda9..ce2a80adaa 100644
--- a/src/nvim/quickfix.c
+++ b/src/nvim/quickfix.c
@@ -1379,14 +1379,16 @@ void qf_jump(qf_info_T *qi, int dir, int errornr, int forceit)
* For ":helpgrep" find a help window or open one.
*/
if (qf_ptr->qf_type == 1 && (!curwin->w_buffer->b_help || cmdmod.tab != 0)) {
- win_T *wp;
+ win_T *wp = NULL;
- 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)
+ if (cmdmod.tab == 0) {
+ FOR_ALL_WINDOWS(wp2) {
+ 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 {
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index c7d9ce28af..a84d3490f0 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -4553,13 +4553,13 @@ void rl_mirror(char_u *str)
*/
void status_redraw_all(void)
{
- 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;
redraw_later(VALID);
}
+ }
}
/*
@@ -4567,13 +4567,12 @@ void status_redraw_all(void)
*/
void status_redraw_curbuf(void)
{
- 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;
redraw_later(VALID);
}
+ }
}
/*
@@ -4581,11 +4580,11 @@ void status_redraw_curbuf(void)
*/
void redraw_statuslines(void)
{
- win_T *wp;
-
- for (wp = firstwin; wp; wp = wp->w_next)
- if (wp->w_redr_status)
+ FOR_ALL_WINDOWS(wp) {
+ if (wp->w_redr_status) {
win_redr_status(wp);
+ }
+ }
if (redraw_tabline)
draw_tabline();
}
diff --git a/src/nvim/spell.c b/src/nvim/spell.c
index d277d71d99..5e40ae7708 100644
--- a/src/nvim/spell.c
+++ b/src/nvim/spell.c
@@ -4155,8 +4155,6 @@ void spell_free_all(void)
// Used after 'encoding' is set and when ":mkspell" was used.
void spell_reload(void)
{
- win_T *wp;
-
// Initialize the table for spell_iswordp().
init_spell_chartab();
@@ -4164,7 +4162,7 @@ void spell_reload(void)
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.
if (*wp->w_s->b_p_spl != NUL) {
diff --git a/src/nvim/window.c b/src/nvim/window.c
index 234788c415..0693e50bda 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -982,13 +982,13 @@ static void win_init_some(win_T *newp, win_T *oldp)
*/
int win_valid(win_T *win)
{
- win_T *wp;
-
if (win == NULL)
return FALSE;
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
- if (wp == win)
+ FOR_ALL_WINDOWS(wp) {
+ if (wp == win) {
return TRUE;
+ }
+ }
return FALSE;
}
@@ -997,11 +997,11 @@ int win_valid(win_T *win)
*/
int win_count(void)
{
- win_T *wp;
int count = 0;
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ FOR_ALL_WINDOWS(wp) {
++count;
+ }
return count;
}
@@ -3475,14 +3475,14 @@ static void win_enter_ext(win_T *wp, bool undo_sync, int curwin_invalid, int tri
*/
win_T *buf_jump_open_win(buf_T *buf)
{
- win_T *wp;
+ FOR_ALL_WINDOWS(wp) {
+ if (wp->w_buffer == buf) {
+ win_enter(wp, false);
+ return wp;
+ }
+ }
- for (wp = firstwin; wp != NULL; wp = wp->w_next)
- if (wp->w_buffer == buf)
- break;
- if (wp != NULL)
- win_enter(wp, false);
- return wp;
+ return NULL;
}
/*
@@ -3784,11 +3784,9 @@ void shell_new_columns(void)
void win_size_save(garray_T *gap)
{
- win_T *wp;
-
ga_init(gap, (int)sizeof(int), 1);
ga_grow(gap, win_count() * 2);
- 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;
((int *)gap->ga_data)[gap->ga_len++] = wp->w_height;
@@ -3801,11 +3799,9 @@ void win_size_save(garray_T *gap)
*/
void win_size_restore(garray_T *gap)
{
- win_T *wp;
-
if (win_count() * 2 == gap->ga_len) {
int 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);
}
@@ -4233,14 +4229,14 @@ void win_setminheight(void)
{
int room;
int first = TRUE;
- win_T *wp;
/* loop until there is a 'winminheight' that is possible */
while (p_wmh > 0) {
/* 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;
--p_wmh;
@@ -4931,20 +4927,21 @@ int min_rows(void)
int only_one_window(void)
{
int count = 0;
- win_T *wp;
/* If there is another tab page there always is another window. */
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)
|| wp->w_p_pvw
) || wp == curwin)
&& wp != aucmd_win
- )
+ ) {
++count;
+ }
+ }
return count <= 1;
}