FOR_ALL_TABS helper

This commit is contained in:
Wayne Rowcliffe
2014-08-22 22:40:49 -05:00
parent a4b9e0df67
commit b4ec6c1a4b
7 changed files with 58 additions and 51 deletions

View File

@@ -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.

View File

@@ -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)
{
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);

View File

@@ -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);

View File

@@ -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,11 +5284,13 @@ 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;
}
}
}
}
/*
* Close the current tab page.
@@ -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 ? '>' : ' ');

View File

@@ -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.

View File

@@ -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)

View File

@@ -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,19 +4963,16 @@ 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 */
return total;