aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2014-09-08 20:50:44 -0400
committerJustin M. Keyes <justinkz@gmail.com>2014-09-08 20:50:44 -0400
commit9fa467a9b227243c9c534ae0df1bdaf8235551a0 (patch)
tree85449173705a443081b1189a9d1087df74030703 /src
parent3f5482d3251b3bbdc7c4df8a8e64eb3af7e5922c (diff)
parentac0b9714edbb7697b8324f922024401baea8953b (diff)
downloadrneovim-9fa467a9b227243c9c534ae0df1bdaf8235551a0.tar.gz
rneovim-9fa467a9b227243c9c534ae0df1bdaf8235551a0.tar.bz2
rneovim-9fa467a9b227243c9c534ae0df1bdaf8235551a0.zip
Merge pull request #1096 from war1025/dev/local_for_all_windows
Convert FOR_ALL_WINDOWS to use a locally declared pointer
Diffstat (limited to 'src')
-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.c38
-rw-r--r--src/nvim/ex_docmd.c14
-rw-r--r--src/nvim/fileio.c13
-rw-r--r--src/nvim/fold.c12
-rw-r--r--src/nvim/globals.h2
-rw-r--r--src/nvim/main.c5
-rw-r--r--src/nvim/mark.c31
-rw-r--r--src/nvim/misc1.c19
-rw-r--r--src/nvim/normal.c5
-rw-r--r--src/nvim/ops.c10
-rw-r--r--src/nvim/option.c14
-rw-r--r--src/nvim/quickfix.c79
-rw-r--r--src/nvim/screen.c97
-rw-r--r--src/nvim/spell.c4
-rw-r--r--src/nvim/syntax.c17
-rw-r--r--src/nvim/undo.c8
-rw-r--r--src/nvim/window.c62
21 files changed, 259 insertions, 275 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 ac91b2a6ac..f1524ffce9 100644
--- a/src/nvim/ex_cmds2.c
+++ b/src/nvim/ex_cmds2.c
@@ -1206,7 +1206,6 @@ check_changed_any (
int bufcount = 0;
int *bufnrs;
tabpage_T *tp;
- win_T *wp;
FOR_ALL_BUFFERS(buf) {
++bufcount;
@@ -1220,15 +1219,21 @@ check_changed_any (
/* curbuf */
bufnrs[bufnum++] = curbuf->b_fnum;
/* buf in curtab */
- FOR_ALL_WINDOWS(wp)
- if (wp->w_buffer != curbuf)
- add_bufnum(bufnrs, &bufnum, wp->w_buffer->b_fnum);
+ FOR_ALL_WINDOWS(wp) {
+ if (wp->w_buffer != curbuf) {
+ add_bufnum(bufnrs, &bufnum, wp->w_buffer->b_fnum);
+ }
+ }
/* buf in other tab */
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
- if (tp != curtab)
- for (wp = tp->tp_firstwin; wp != NULL; wp = wp->w_next)
+ for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) {
+ if (tp != curtab) {
+ for (win_T *wp = tp->tp_firstwin; wp != NULL; wp = wp->w_next) {
add_bufnum(bufnrs, &bufnum, wp->w_buffer->b_fnum);
+ }
+ }
+ }
+
/* any other buf */
FOR_ALL_BUFFERS(buf) {
add_bufnum(bufnrs, &bufnum, buf->b_fnum);
@@ -1277,16 +1282,19 @@ check_changed_any (
}
/* Try to find a window that contains the buffer. */
- if (buf != curbuf)
- FOR_ALL_TAB_WINDOWS(tp, wp)
- if (wp->w_buffer == buf) {
- goto_tabpage_win(tp, wp);
- /* Paranoia: did autocms wipe out the buffer with changes? */
- if (!buf_valid(buf)) {
- goto theend;
+ if (buf != curbuf) {
+ win_T *wp;
+ FOR_ALL_TAB_WINDOWS(tp, wp) {
+ if (wp->w_buffer == buf) {
+ goto_tabpage_win(tp, wp);
+ /* Paranoia: did autocms wipe out the buffer with changes? */
+ if (!buf_valid(buf)) {
+ goto theend;
+ }
+ goto buf_found;
}
- 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/fold.c b/src/nvim/fold.c
index f65bbc0875..186e75981e 100644
--- a/src/nvim/fold.c
+++ b/src/nvim/fold.c
@@ -460,13 +460,10 @@ void newFoldLevel(void)
newFoldLevelWin(curwin);
if (foldmethodIsDiff(curwin) && curwin->w_p_scb) {
- win_T *wp;
-
/*
* Set the same foldlevel in other windows in diff mode.
*/
- FOR_ALL_WINDOWS(wp)
- {
+ FOR_ALL_WINDOWS(wp) {
if (wp != curwin && foldmethodIsDiff(wp) && wp->w_p_scb) {
wp->w_p_fdl = curwin->w_p_fdl;
newFoldLevelWin(wp);
@@ -1140,19 +1137,18 @@ setManualFold (
)
{
if (foldmethodIsDiff(curwin) && curwin->w_p_scb) {
- win_T *wp;
linenr_T dlnum;
/*
* Do the same operation in other windows in diff mode. Calculate the
* line number from the diffs.
*/
- FOR_ALL_WINDOWS(wp)
- {
+ FOR_ALL_WINDOWS(wp) {
if (wp != curwin && foldmethodIsDiff(wp) && wp->w_p_scb) {
dlnum = diff_lnum_win(curwin->w_cursor.lnum, wp);
- if (dlnum != 0)
+ if (dlnum != 0) {
(void)setManualFoldWin(wp, dlnum, opening, recurse, NULL);
+ }
}
}
}
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index 1ff8887598..3b9a9ae64b 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -519,7 +519,7 @@ EXTERN win_T *firstwin; /* first window */
EXTERN win_T *lastwin; /* last window */
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_WINDOWS(wp) for (win_T *wp = firstwin; wp != NULL; 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.
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/mark.c b/src/nvim/mark.c
index 43469cab45..6339cf8275 100644
--- a/src/nvim/mark.c
+++ b/src/nvim/mark.c
@@ -500,7 +500,6 @@ void fmarks_check_names(buf_T *buf)
{
char_u *name;
int i;
- win_T *wp;
if (buf->b_ffname == NULL)
return;
@@ -512,10 +511,10 @@ void fmarks_check_names(buf_T *buf)
for (i = 0; i < NMARKS + EXTRA_MARKS; ++i)
fmarks_check_one(&namedfm[i], name, buf);
- FOR_ALL_WINDOWS(wp)
- {
- for (i = 0; i < wp->w_jumplistlen; ++i)
+ FOR_ALL_WINDOWS(wp) {
+ for (i = 0; i < wp->w_jumplistlen; ++i) {
fmarks_check_one(&wp->w_jumplist[i], name, buf);
+ }
}
free(name);
@@ -1042,7 +1041,6 @@ void mark_col_adjust(linenr_T lnum, colnr_T mincol, long lnum_amount, long col_a
{
int i;
int fnum = curbuf->b_fnum;
- win_T *win;
pos_T *posp;
if ((col_amount == 0L && lnum_amount == 0L) || cmdmod.lockmarks)
@@ -1085,22 +1083,26 @@ void mark_col_adjust(linenr_T lnum, colnr_T mincol, long lnum_amount, long col_a
/*
* Adjust items in all windows related to the current buffer.
*/
- FOR_ALL_WINDOWS(win)
- {
+ FOR_ALL_WINDOWS(win) {
/* marks in the jumplist */
- for (i = 0; i < win->w_jumplistlen; ++i)
- if (win->w_jumplist[i].fmark.fnum == fnum)
+ for (i = 0; i < win->w_jumplistlen; ++i) {
+ if (win->w_jumplist[i].fmark.fnum == fnum) {
col_adjust(&(win->w_jumplist[i].fmark.mark));
+ }
+ }
if (win->w_buffer == curbuf) {
/* marks in the tag stack */
- for (i = 0; i < win->w_tagstacklen; i++)
- if (win->w_tagstack[i].fmark.fnum == fnum)
+ for (i = 0; i < win->w_tagstacklen; i++) {
+ if (win->w_tagstack[i].fmark.fnum == fnum) {
col_adjust(&(win->w_tagstack[i].fmark.mark));
+ }
+ }
/* cursor position for other windows with the same buffer */
- if (win != curwin)
+ if (win != curwin) {
col_adjust(&win->w_cursor);
+ }
}
}
}
@@ -1526,10 +1528,7 @@ void copy_viminfo_marks(vir_T *virp, FILE *fp_out, int count, int eof, int flags
fputs((char *)line, fp_out);
}
if (load_marks) {
- win_T *wp;
-
- FOR_ALL_WINDOWS(wp)
- {
+ FOR_ALL_WINDOWS(wp) {
if (wp->w_buffer == curbuf)
wp->w_changelistidx = curbuf->b_changelistlen;
}
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/normal.c b/src/nvim/normal.c
index 55b86f61dd..cc82630548 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -4008,12 +4008,9 @@ dozet:
/* Redraw when 'foldenable' changed */
if (old_fen != curwin->w_p_fen) {
- win_T *wp;
-
if (foldmethodIsDiff(curwin) && curwin->w_p_scb) {
/* Adjust 'foldenable' in diff-synced windows. */
- FOR_ALL_WINDOWS(wp)
- {
+ FOR_ALL_WINDOWS(wp) {
if (wp != curwin && foldmethodIsDiff(wp) && wp->w_p_scb) {
wp->w_p_fen = curwin->w_p_fen;
changed_window_setting_win(wp);
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index f1cb34577b..317d773748 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -3698,17 +3698,15 @@ op_format (
}
if (oap->is_VIsual) {
- win_T *wp;
-
- FOR_ALL_WINDOWS(wp)
- {
+ FOR_ALL_WINDOWS(wp) {
if (wp->w_old_cursor_lnum != 0) {
/* When lines have been inserted or deleted, adjust the end of
* the Visual area to be redrawn. */
- if (wp->w_old_cursor_lnum > wp->w_old_visual_lnum)
+ if (wp->w_old_cursor_lnum > wp->w_old_visual_lnum) {
wp->w_old_cursor_lnum += old_line_count;
- else
+ } else {
wp->w_old_visual_lnum += old_line_count;
+ }
}
}
}
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 6eac1033c4..b9becebbf4 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -4306,7 +4306,6 @@ did_set_string_option (
/* When 'spelllang' or 'spellfile' is set and there is a window for this
* buffer in which 'spell' is set load the wordlists. */
else if (varp == &(curbuf->b_s.b_p_spl) || varp == &(curbuf->b_s.b_p_spf)) {
- win_T *wp;
int l;
if (varp == &(curbuf->b_s.b_p_spf)) {
@@ -4317,10 +4316,11 @@ did_set_string_option (
}
if (errmsg == NULL) {
- FOR_ALL_WINDOWS(wp)
- if (wp->w_buffer == curbuf && wp->w_p_spell) {
- errmsg = did_set_spelllang(wp);
- break;
+ FOR_ALL_WINDOWS(wp) {
+ if (wp->w_buffer == curbuf && wp->w_p_spell) {
+ errmsg = did_set_spelllang(wp);
+ break;
+ }
}
}
}
@@ -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 876d4e73d1..ce2a80adaa 100644
--- a/src/nvim/quickfix.c
+++ b/src/nvim/quickfix.c
@@ -1294,7 +1294,7 @@ void qf_jump(qf_info_T *qi, int dir, int errornr, int forceit)
int len;
int old_KeyTyped = KeyTyped; /* getting file may reset it */
int ok = OK;
- int usable_win;
+ bool usable_win;
if (qi == NULL)
qi = &ql_info;
@@ -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 {
@@ -1433,26 +1435,29 @@ void qf_jump(qf_info_T *qi, int dir, int errornr, int forceit)
if (qf_ptr->qf_fnum == 0)
goto theend;
- usable_win = 0;
+ usable_win = false;
ll_ref = curwin->w_llist_ref;
if (ll_ref != NULL) {
/* Find a window using the same location list that is not a
* quickfix window. */
- FOR_ALL_WINDOWS(usable_win_ptr)
- if (usable_win_ptr->w_llist == ll_ref
- && usable_win_ptr->w_buffer->b_p_bt[0] != 'q') {
- usable_win = 1;
- break;
+ FOR_ALL_WINDOWS(wp) {
+ if (wp->w_llist == ll_ref
+ && wp->w_buffer->b_p_bt[0] != 'q') {
+ usable_win = true;
+ usable_win_ptr = wp;
+ break;
+ }
}
}
if (!usable_win) {
/* Locate a window showing a normal buffer */
- FOR_ALL_WINDOWS(win)
- if (win->w_buffer->b_p_bt[0] == NUL) {
- usable_win = 1;
- break;
+ FOR_ALL_WINDOWS(wp) {
+ if (wp->w_buffer->b_p_bt[0] == NUL) {
+ usable_win = true;
+ break;
+ }
}
}
@@ -1468,7 +1473,7 @@ void qf_jump(qf_info_T *qi, int dir, int errornr, int forceit)
{
if (wp->w_buffer->b_fnum == qf_ptr->qf_fnum) {
goto_tabpage_win(tp, wp);
- usable_win = 1;
+ usable_win = true;
goto win_found;
}
}
@@ -1501,9 +1506,12 @@ win_found:
win = usable_win_ptr;
if (win == NULL) {
/* Find the window showing the selected file */
- FOR_ALL_WINDOWS(win)
- if (win->w_buffer->b_fnum == qf_ptr->qf_fnum)
- break;
+ FOR_ALL_WINDOWS(wp) {
+ if (wp->w_buffer->b_fnum == qf_ptr->qf_fnum) {
+ win = wp;
+ break;
+ }
+ }
if (win == NULL) {
/* Find a previous usable window */
win = curwin;
@@ -2212,13 +2220,13 @@ static int is_qf_win(win_T *win, qf_info_T *qi)
*/
static win_T *qf_find_win(qf_info_T *qi)
{
- win_T *win;
-
- FOR_ALL_WINDOWS(win)
- if (is_qf_win(win, qi))
- break;
+ FOR_ALL_WINDOWS(win) {
+ if (is_qf_win(win, qi)) {
+ return win;
+ }
+ }
- return win;
+ return NULL;
}
/*
@@ -3478,7 +3486,6 @@ void ex_helpgrep(exarg_T *eap)
char_u *lang;
qf_info_T *qi = &ql_info;
int new_qi = FALSE;
- win_T *wp;
char_u *au_name = NULL;
/* Check for a specified language */
@@ -3501,16 +3508,16 @@ void ex_helpgrep(exarg_T *eap)
p_cpo = empty_option;
if (eap->cmdidx == CMD_lhelpgrep) {
- /* Find an existing help window */
- FOR_ALL_WINDOWS(wp)
- if (wp->w_buffer != NULL && wp->w_buffer->b_help)
- break;
+ qi = NULL;
- if (wp == NULL) /* Help window not found */
- qi = NULL;
- else
- qi = wp->w_llist;
+ /* Find an existing help window */
+ FOR_ALL_WINDOWS(wp) {
+ if (wp->w_buffer != NULL && wp->w_buffer->b_help) {
+ qi = wp->w_llist;
+ }
+ }
+ /* Help window not found */
if (qi == NULL) {
/* Allocate a new location list for help text matches */
qi = ll_new_list();
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index 91db983525..a84d3490f0 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -206,10 +206,7 @@ void redraw_later_clear(void)
*/
void redraw_all_later(int type)
{
- win_T *wp;
-
- FOR_ALL_WINDOWS(wp)
- {
+ FOR_ALL_WINDOWS(wp) {
redraw_win_later(wp, type);
}
}
@@ -224,12 +221,10 @@ void redraw_curbuf_later(int type)
void redraw_buf_later(buf_T *buf, int type)
{
- win_T *wp;
-
- FOR_ALL_WINDOWS(wp)
- {
- if (wp->w_buffer == buf)
+ FOR_ALL_WINDOWS(wp) {
+ if (wp->w_buffer == buf) {
redraw_win_later(wp, type);
+ }
}
}
@@ -390,7 +385,6 @@ void update_curbuf(int type)
*/
void update_screen(int type)
{
- win_T *wp;
static int did_intro = FALSE;
int did_one;
@@ -438,8 +432,7 @@ void update_screen(int type)
check_for_delay(FALSE);
if (screen_ins_lines(0, 0, msg_scrolled, (int)Rows, NULL) == FAIL)
type = CLEAR;
- FOR_ALL_WINDOWS(wp)
- {
+ FOR_ALL_WINDOWS(wp) {
if (wp->w_winrow < msg_scrolled) {
if (wp->w_winrow + wp->w_height > msg_scrolled
&& wp->w_redr_type < REDRAW_TOP
@@ -450,8 +443,9 @@ void update_screen(int type)
} else {
wp->w_redr_type = NOT_VALID;
if (wp->w_winrow + wp->w_height + wp->w_status_height
- <= msg_scrolled)
+ <= msg_scrolled) {
wp->w_redr_status = TRUE;
+ }
}
}
}
@@ -512,8 +506,7 @@ void update_screen(int type)
* Correct stored syntax highlighting info for changes in each displayed
* buffer. Each buffer must only be done once.
*/
- FOR_ALL_WINDOWS(wp)
- {
+ FOR_ALL_WINDOWS(wp) {
if (wp->w_buffer->b_mod_set) {
win_T *wwp;
@@ -534,8 +527,7 @@ void update_screen(int type)
*/
did_one = FALSE;
search_hl.rm.regprog = NULL;
- FOR_ALL_WINDOWS(wp)
- {
+ FOR_ALL_WINDOWS(wp) {
if (wp->w_redr_type != 0) {
cursor_off();
if (!did_one) {
@@ -558,8 +550,9 @@ void update_screen(int type)
/* 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;
+ }
updating_screen = FALSE;
@@ -662,31 +655,28 @@ static void update_finish(void)
void update_debug_sign(buf_T *buf, linenr_T lnum)
{
- win_T *wp;
int doit = FALSE;
win_foldinfo.fi_level = 0;
/* update/delete a specific mark */
- FOR_ALL_WINDOWS(wp)
- {
- if (buf != NULL && lnum > 0) {
- if (wp->w_buffer == buf && lnum >= wp->w_topline
- && lnum < wp->w_botline)
- {
- if (wp->w_redraw_top == 0 || wp->w_redraw_top > lnum) {
- wp->w_redraw_top = lnum;
- }
- if (wp->w_redraw_bot == 0 || wp->w_redraw_bot < lnum) {
- wp->w_redraw_bot = lnum;
- }
- redraw_win_later(wp, VALID);
- }
- } else {
- redraw_win_later(wp, VALID);
- }
- if (wp->w_redr_type != 0) {
- doit = TRUE;
+ FOR_ALL_WINDOWS(wp) {
+ if (buf != NULL && lnum > 0) {
+ if (wp->w_buffer == buf && lnum >= wp->w_topline
+ && lnum < wp->w_botline) {
+ if (wp->w_redraw_top == 0 || wp->w_redraw_top > lnum) {
+ wp->w_redraw_top = lnum;
+ }
+ if (wp->w_redraw_bot == 0 || wp->w_redraw_bot < lnum) {
+ wp->w_redraw_bot = lnum;
+ }
+ redraw_win_later(wp, VALID);
}
+ } else {
+ redraw_win_later(wp, VALID);
+ }
+ if (wp->w_redr_type != 0) {
+ doit = TRUE;
+ }
}
/* Return when there is nothing to do, screen updating is already
@@ -698,13 +688,13 @@ void update_debug_sign(buf_T *buf, linenr_T lnum)
/* update all windows that need updating */
update_prepare();
- for (wp = firstwin; wp; wp = wp->w_next) {
- if (wp->w_redr_type != 0) {
- win_update(wp);
- }
- if (wp->w_redr_status) {
- win_redr_status(wp);
- }
+ FOR_ALL_WINDOWS(wp) {
+ if (wp->w_redr_type != 0) {
+ win_update(wp);
+ }
+ if (wp->w_redr_status) {
+ win_redr_status(wp);
+ }
}
update_finish();
@@ -4563,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);
}
+ }
}
/*
@@ -4577,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);
}
+ }
}
/*
@@ -4591,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/syntax.c b/src/nvim/syntax.c
index 5f6e09925e..5001d6498e 100644
--- a/src/nvim/syntax.c
+++ b/src/nvim/syntax.c
@@ -984,16 +984,13 @@ static void syn_stack_free_block(synblock_T *block)
*/
void syn_stack_free_all(synblock_T *block)
{
- win_T *wp;
-
syn_stack_free_block(block);
-
/* When using "syntax" fold method, must update all folds. */
- FOR_ALL_WINDOWS(wp)
- {
- if (wp->w_s == block && foldmethodIsSyntax(wp))
+ FOR_ALL_WINDOWS(wp) {
+ if (wp->w_s == block && foldmethodIsSyntax(wp)) {
foldUpdateAll(wp);
+ }
}
}
@@ -1075,14 +1072,12 @@ static void syn_stack_alloc(void)
*/
void syn_stack_apply_changes(buf_T *buf)
{
- win_T *wp;
-
syn_stack_apply_changes_block(&buf->b_s, buf);
- FOR_ALL_WINDOWS(wp)
- {
- if ((wp->w_buffer == buf) && (wp->w_s != &buf->b_s))
+ FOR_ALL_WINDOWS(wp) {
+ if ((wp->w_buffer == buf) && (wp->w_s != &buf->b_s)) {
syn_stack_apply_changes_block(wp->w_s, buf);
+ }
}
}
diff --git a/src/nvim/undo.c b/src/nvim/undo.c
index d7a691aa83..9fbe21aeb0 100644
--- a/src/nvim/undo.c
+++ b/src/nvim/undo.c
@@ -2191,12 +2191,10 @@ u_undo_end (
u_add_time(msgbuf, sizeof(msgbuf), uhp->uh_time);
{
- win_T *wp;
-
- FOR_ALL_WINDOWS(wp)
- {
- if (wp->w_buffer == curbuf && wp->w_p_cole > 0)
+ FOR_ALL_WINDOWS(wp) {
+ if (wp->w_buffer == curbuf && wp->w_p_cole > 0) {
redraw_win_later(wp, NOT_VALID);
+ }
}
}
diff --git a/src/nvim/window.c b/src/nvim/window.c
index becc21be89..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;
}
@@ -1677,20 +1677,19 @@ static int last_window(void)
* Return TRUE if there is only one window other than "aucmd_win" in the
* current tab page.
*/
-int one_window(void)
+bool one_window(void)
{
- win_T *wp;
- int seen_one = FALSE;
+ bool seen_one = false;
- FOR_ALL_WINDOWS(wp)
- {
+ FOR_ALL_WINDOWS(wp) {
if (wp != aucmd_win) {
- if (seen_one)
- return FALSE;
- seen_one = TRUE;
+ if (seen_one) {
+ return false;
+ }
+ seen_one = true;
}
}
- return TRUE;
+ return true;
}
/*
@@ -3476,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;
}
/*
@@ -3785,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;
@@ -3802,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);
}
@@ -4234,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;
@@ -4932,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;
}