aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/diff.c21
-rw-r--r--src/nvim/eval.c12
-rw-r--r--src/nvim/ex_cmds2.c4
-rw-r--r--src/nvim/ex_docmd.c26
-rw-r--r--src/nvim/globals.h3
-rw-r--r--src/nvim/screen.c12
-rw-r--r--src/nvim/window.c31
7 files changed, 58 insertions, 51 deletions
diff --git a/src/nvim/diff.c b/src/nvim/diff.c
index 8f540fbe09..7927473439 100644
--- a/src/nvim/diff.c
+++ b/src/nvim/diff.c
@@ -62,8 +62,7 @@ static int diff_a_works = MAYBE;
/// @param buf
void diff_buf_delete(buf_T *buf)
{
- tabpage_T *tp;
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) {
+ FOR_ALL_TABS(tp) {
int i = diff_buf_idx_tp(buf, tp);
if (i != DB_COUNT) {
@@ -175,8 +174,7 @@ static int diff_buf_idx_tp(buf_T *buf, tabpage_T *tp)
/// @param buf
void diff_invalidate(buf_T *buf)
{
- tabpage_T *tp;
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) {
+ FOR_ALL_TABS(tp) {
int i = diff_buf_idx_tp(buf, tp);
if (i != DB_COUNT) {
tp->tp_diff_invalid = TRUE;
@@ -197,8 +195,7 @@ void diff_mark_adjust(linenr_T line1, linenr_T line2, long amount,
long amount_after)
{
// Handle all tab pages that use the current buffer in a diff.
- tabpage_T *tp;
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) {
+ FOR_ALL_TABS(tp) {
int idx = diff_buf_idx_tp(curbuf, tp);
if (idx != DB_COUNT) {
diff_mark_adjust_tp(tp, idx, line1, line2, amount, amount_after);
@@ -1819,8 +1816,7 @@ int diffopt_changed(void)
// If "icase" or "iwhite" was added or removed, need to update the diff.
if (diff_flags != diff_flags_new) {
- tabpage_T *tp;
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) {
+ FOR_ALL_TABS(tp) {
tp->tp_diff_invalid = TRUE;
}
}
@@ -2376,15 +2372,14 @@ static void diff_fold_update(diff_T *dp, int skip_idx)
/// @param buf The buffer to check.
///
/// @return TRUE if buffer "buf" is in diff-mode.
-int diff_mode_buf(buf_T *buf)
+bool diff_mode_buf(buf_T *buf)
{
- tabpage_T *tp;
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) {
+ FOR_ALL_TABS(tp) {
if (diff_buf_idx_tp(buf, tp) != DB_COUNT) {
- return TRUE;
+ return true;
}
}
- return FALSE;
+ return false;
}
/// Move "count" times in direction "dir" to the next diff block.
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 0dd261f53a..413edc9271 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -5407,7 +5407,6 @@ int garbage_collect(void)
funccall_T *fc, **pfc;
int did_free;
int did_free_funccal = FALSE;
- tabpage_T *tp;
/* Only do this once. */
want_garbage_collect = FALSE;
@@ -5442,14 +5441,19 @@ int garbage_collect(void)
}
/* window-local variables */
- FOR_ALL_TAB_WINDOWS(tp, wp)
- set_ref_in_item(&wp->w_winvar.di_tv, copyID);
+ {
+ tabpage_T *tp;
+ FOR_ALL_TAB_WINDOWS(tp, wp) {
+ set_ref_in_item(&wp->w_winvar.di_tv, copyID);
+ }
+ }
if (aucmd_win != NULL)
set_ref_in_item(&aucmd_win->w_winvar.di_tv, copyID);
/* tabpage-local variables */
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+ FOR_ALL_TABS(tp) {
set_ref_in_item(&tp->tp_winvar.di_tv, copyID);
+ }
/* global variables */
set_ref_in_ht(&globvarht, copyID);
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c
index c3d34e9991..37d59b8fcf 100644
--- a/src/nvim/ex_cmds2.c
+++ b/src/nvim/ex_cmds2.c
@@ -1204,7 +1204,6 @@ check_changed_any (
int bufnum = 0;
int bufcount = 0;
int *bufnrs;
- tabpage_T *tp;
FOR_ALL_BUFFERS(buf) {
++bufcount;
@@ -1225,7 +1224,7 @@ check_changed_any (
}
/* buf in other tab */
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) {
+ FOR_ALL_TABS(tp) {
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);
@@ -1283,6 +1282,7 @@ check_changed_any (
/* Try to find a window that contains the buffer. */
if (buf != curbuf) {
win_T *wp;
+ tabpage_T *tp;
FOR_ALL_TAB_WINDOWS(tp, wp) {
if (wp->w_buffer == buf) {
goto_tabpage_win(tp, wp);
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 1117b6fbcf..61f4f37823 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -5267,9 +5267,6 @@ static void ex_tabclose(exarg_T *eap)
*/
static void ex_tabonly(exarg_T *eap)
{
- tabpage_T *tp;
- int done;
-
if (cmdwin_type != 0)
cmdwin_result = K_IGNORE;
else if (first_tabpage->tp_next == NULL)
@@ -5277,8 +5274,8 @@ static void ex_tabonly(exarg_T *eap)
else {
/* Repeat this up to a 1000 times, because autocommands may mess
* up the lists. */
- for (done = 0; done < 1000; ++done) {
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+ for (int done = 0; done < 1000; ++done) {
+ FOR_ALL_TABS(tp) {
if (tp->tp_topframe != topframe) {
tabpage_close_other(tp, eap->forceit);
/* if we failed to close it quit */
@@ -5287,8 +5284,10 @@ static void ex_tabonly(exarg_T *eap)
/* start over, "tp" is now invalid */
break;
}
- if (first_tabpage->tp_next == NULL)
+ }
+ if (first_tabpage->tp_next == NULL) {
break;
+ }
}
}
}
@@ -5808,23 +5807,28 @@ static void ex_tabmove(exarg_T *eap)
*/
static void ex_tabs(exarg_T *eap)
{
- tabpage_T *tp;
- win_T *wp;
int tabcount = 1;
msg_start();
msg_scroll = TRUE;
- for (tp = first_tabpage; tp != NULL && !got_int; tp = tp->tp_next) {
+
+ FOR_ALL_TABS(tp) {
+ if (got_int) {
+ break;
+ }
+
msg_putchar('\n');
vim_snprintf((char *)IObuff, IOSIZE, _("Tab page %d"), tabcount++);
msg_outtrans_attr(IObuff, hl_attr(HLF_T));
out_flush(); /* output one line at a time */
ui_breakcheck();
- if (tp == curtab)
+ win_T *wp;
+ if (tp == curtab) {
wp = firstwin;
- else
+ } else {
wp = tp->tp_firstwin;
+ }
for (; wp != NULL && !got_int; wp = wp->w_next) {
msg_putchar('\n');
msg_putchar(wp == curwin ? '>' : ' ');
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index 851022cd62..a7aaf6429c 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -548,6 +548,9 @@ EXTERN tabpage_T *first_tabpage;
EXTERN tabpage_T *curtab;
EXTERN int redraw_tabline INIT(= FALSE); /* need to redraw tabline */
+// Iterates over all tabs in the tab list
+# define FOR_ALL_TABS(tp) for (tabpage_T *tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+
/*
* All buffers are linked in a list. 'firstbuf' points to the first entry,
* 'lastbuf' to the last entry and 'curbuf' to the currently active buffer.
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index 122c23ed84..327f39f096 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -7632,7 +7632,6 @@ void unshowmode(int force)
static void draw_tabline(void)
{
int tabcount = 0;
- tabpage_T *tp;
int tabwidth;
int col = 0;
int scol = 0;
@@ -7675,8 +7674,9 @@ static void draw_tabline(void)
(char_u *)"", OPT_FREE, SID_ERROR);
called_emsg |= save_called_emsg;
} else {
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+ FOR_ALL_TABS(tp) {
++tabcount;
+ }
tabwidth = (Columns - 1 + tabcount / 2) / tabcount;
if (tabwidth < 6)
@@ -7685,8 +7685,12 @@ static void draw_tabline(void)
attr = attr_nosel;
tabcount = 0;
scol = 0;
- for (tp = first_tabpage; tp != NULL && col < Columns - 4;
- tp = tp->tp_next) {
+
+ FOR_ALL_TABS(tp) {
+ if (col >= Columns - 4) {
+ break;
+ }
+
scol = col;
if (tp->tp_topframe == topframe)
diff --git a/src/nvim/window.c b/src/nvim/window.c
index f5d8edc751..6af2087076 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -2986,14 +2986,14 @@ int make_tabpages(int maxcount)
/*
* Return TRUE when "tpc" points to a valid tab page.
*/
-int valid_tabpage(tabpage_T *tpc)
+bool valid_tabpage(tabpage_T *tpc)
{
- tabpage_T *tp;
-
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
- if (tp == tpc)
- return TRUE;
- return FALSE;
+ FOR_ALL_TABS(tp) {
+ if (tp == tpc) {
+ return true;
+ }
+ }
+ return false;
}
/*
@@ -3550,14 +3550,13 @@ win_T *buf_jump_open_win(buf_T *buf)
win_T *buf_jump_open_tab(buf_T *buf)
{
win_T *wp;
- tabpage_T *tp;
/* First try the current tab page. */
wp = buf_jump_open_win(buf);
if (wp != NULL)
return wp;
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+ FOR_ALL_TABS(tp) {
if (tp != curtab) {
for (wp = tp->tp_firstwin; wp != NULL; wp = wp->w_next)
if (wp->w_buffer == buf)
@@ -3569,6 +3568,7 @@ win_T *buf_jump_open_tab(buf_T *buf)
break;
}
}
+ }
return wp;
}
@@ -4963,18 +4963,15 @@ int tabline_height(void)
*/
int min_rows(void)
{
- int total;
- tabpage_T *tp;
- int n;
-
if (firstwin == NULL) /* not initialized yet */
return MIN_LINES;
- total = 0;
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) {
- n = frame_minheight(tp->tp_topframe, NULL);
- if (total < n)
+ int total = 0;
+ FOR_ALL_TABS(tp) {
+ int n = frame_minheight(tp->tp_topframe, NULL);
+ if (total < n) {
total = n;
+ }
}
total += tabline_height();
total += 1; /* count the room for the command line */