mirror of
https://github.com/neovim/neovim.git
synced 2025-09-15 07:48:18 +00:00
FOR_ALL_TABS helper
This commit is contained in:
@@ -62,8 +62,7 @@ static int diff_a_works = MAYBE;
|
|||||||
/// @param buf
|
/// @param buf
|
||||||
void diff_buf_delete(buf_T *buf)
|
void diff_buf_delete(buf_T *buf)
|
||||||
{
|
{
|
||||||
tabpage_T *tp;
|
FOR_ALL_TABS(tp) {
|
||||||
for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) {
|
|
||||||
int i = diff_buf_idx_tp(buf, tp);
|
int i = diff_buf_idx_tp(buf, tp);
|
||||||
|
|
||||||
if (i != DB_COUNT) {
|
if (i != DB_COUNT) {
|
||||||
@@ -175,8 +174,7 @@ static int diff_buf_idx_tp(buf_T *buf, tabpage_T *tp)
|
|||||||
/// @param buf
|
/// @param buf
|
||||||
void diff_invalidate(buf_T *buf)
|
void diff_invalidate(buf_T *buf)
|
||||||
{
|
{
|
||||||
tabpage_T *tp;
|
FOR_ALL_TABS(tp) {
|
||||||
for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) {
|
|
||||||
int i = diff_buf_idx_tp(buf, tp);
|
int i = diff_buf_idx_tp(buf, tp);
|
||||||
if (i != DB_COUNT) {
|
if (i != DB_COUNT) {
|
||||||
tp->tp_diff_invalid = TRUE;
|
tp->tp_diff_invalid = TRUE;
|
||||||
@@ -197,8 +195,7 @@ void diff_mark_adjust(linenr_T line1, linenr_T line2, long amount,
|
|||||||
long amount_after)
|
long amount_after)
|
||||||
{
|
{
|
||||||
// Handle all tab pages that use the current buffer in a diff.
|
// Handle all tab pages that use the current buffer in a diff.
|
||||||
tabpage_T *tp;
|
FOR_ALL_TABS(tp) {
|
||||||
for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) {
|
|
||||||
int idx = diff_buf_idx_tp(curbuf, tp);
|
int idx = diff_buf_idx_tp(curbuf, tp);
|
||||||
if (idx != DB_COUNT) {
|
if (idx != DB_COUNT) {
|
||||||
diff_mark_adjust_tp(tp, idx, line1, line2, amount, amount_after);
|
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 "icase" or "iwhite" was added or removed, need to update the diff.
|
||||||
if (diff_flags != diff_flags_new) {
|
if (diff_flags != diff_flags_new) {
|
||||||
tabpage_T *tp;
|
FOR_ALL_TABS(tp) {
|
||||||
for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) {
|
|
||||||
tp->tp_diff_invalid = TRUE;
|
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.
|
/// @param buf The buffer to check.
|
||||||
///
|
///
|
||||||
/// @return TRUE if buffer "buf" is in diff-mode.
|
/// @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_ALL_TABS(tp) {
|
||||||
for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) {
|
|
||||||
if (diff_buf_idx_tp(buf, tp) != DB_COUNT) {
|
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.
|
/// Move "count" times in direction "dir" to the next diff block.
|
||||||
|
@@ -5407,7 +5407,6 @@ int garbage_collect(void)
|
|||||||
funccall_T *fc, **pfc;
|
funccall_T *fc, **pfc;
|
||||||
int did_free;
|
int did_free;
|
||||||
int did_free_funccal = FALSE;
|
int did_free_funccal = FALSE;
|
||||||
tabpage_T *tp;
|
|
||||||
|
|
||||||
/* Only do this once. */
|
/* Only do this once. */
|
||||||
want_garbage_collect = FALSE;
|
want_garbage_collect = FALSE;
|
||||||
@@ -5442,14 +5441,19 @@ int garbage_collect(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* window-local variables */
|
/* 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)
|
if (aucmd_win != NULL)
|
||||||
set_ref_in_item(&aucmd_win->w_winvar.di_tv, copyID);
|
set_ref_in_item(&aucmd_win->w_winvar.di_tv, copyID);
|
||||||
|
|
||||||
/* tabpage-local variables */
|
/* 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);
|
set_ref_in_item(&tp->tp_winvar.di_tv, copyID);
|
||||||
|
}
|
||||||
|
|
||||||
/* global variables */
|
/* global variables */
|
||||||
set_ref_in_ht(&globvarht, copyID);
|
set_ref_in_ht(&globvarht, copyID);
|
||||||
|
@@ -1204,7 +1204,6 @@ check_changed_any (
|
|||||||
int bufnum = 0;
|
int bufnum = 0;
|
||||||
int bufcount = 0;
|
int bufcount = 0;
|
||||||
int *bufnrs;
|
int *bufnrs;
|
||||||
tabpage_T *tp;
|
|
||||||
|
|
||||||
FOR_ALL_BUFFERS(buf) {
|
FOR_ALL_BUFFERS(buf) {
|
||||||
++bufcount;
|
++bufcount;
|
||||||
@@ -1225,7 +1224,7 @@ check_changed_any (
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* buf in other tab */
|
/* buf in other tab */
|
||||||
for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) {
|
FOR_ALL_TABS(tp) {
|
||||||
if (tp != curtab) {
|
if (tp != curtab) {
|
||||||
for (win_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);
|
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. */
|
/* Try to find a window that contains the buffer. */
|
||||||
if (buf != curbuf) {
|
if (buf != curbuf) {
|
||||||
win_T *wp;
|
win_T *wp;
|
||||||
|
tabpage_T *tp;
|
||||||
FOR_ALL_TAB_WINDOWS(tp, wp) {
|
FOR_ALL_TAB_WINDOWS(tp, wp) {
|
||||||
if (wp->w_buffer == buf) {
|
if (wp->w_buffer == buf) {
|
||||||
goto_tabpage_win(tp, wp);
|
goto_tabpage_win(tp, wp);
|
||||||
|
@@ -5267,9 +5267,6 @@ static void ex_tabclose(exarg_T *eap)
|
|||||||
*/
|
*/
|
||||||
static void ex_tabonly(exarg_T *eap)
|
static void ex_tabonly(exarg_T *eap)
|
||||||
{
|
{
|
||||||
tabpage_T *tp;
|
|
||||||
int done;
|
|
||||||
|
|
||||||
if (cmdwin_type != 0)
|
if (cmdwin_type != 0)
|
||||||
cmdwin_result = K_IGNORE;
|
cmdwin_result = K_IGNORE;
|
||||||
else if (first_tabpage->tp_next == NULL)
|
else if (first_tabpage->tp_next == NULL)
|
||||||
@@ -5277,8 +5274,8 @@ static void ex_tabonly(exarg_T *eap)
|
|||||||
else {
|
else {
|
||||||
/* Repeat this up to a 1000 times, because autocommands may mess
|
/* Repeat this up to a 1000 times, because autocommands may mess
|
||||||
* up the lists. */
|
* up the lists. */
|
||||||
for (done = 0; done < 1000; ++done) {
|
for (int done = 0; done < 1000; ++done) {
|
||||||
for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
|
FOR_ALL_TABS(tp) {
|
||||||
if (tp->tp_topframe != topframe) {
|
if (tp->tp_topframe != topframe) {
|
||||||
tabpage_close_other(tp, eap->forceit);
|
tabpage_close_other(tp, eap->forceit);
|
||||||
/* if we failed to close it quit */
|
/* if we failed to close it quit */
|
||||||
@@ -5287,8 +5284,10 @@ static void ex_tabonly(exarg_T *eap)
|
|||||||
/* start over, "tp" is now invalid */
|
/* start over, "tp" is now invalid */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (first_tabpage->tp_next == NULL)
|
}
|
||||||
|
if (first_tabpage->tp_next == NULL) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5808,23 +5807,28 @@ static void ex_tabmove(exarg_T *eap)
|
|||||||
*/
|
*/
|
||||||
static void ex_tabs(exarg_T *eap)
|
static void ex_tabs(exarg_T *eap)
|
||||||
{
|
{
|
||||||
tabpage_T *tp;
|
|
||||||
win_T *wp;
|
|
||||||
int tabcount = 1;
|
int tabcount = 1;
|
||||||
|
|
||||||
msg_start();
|
msg_start();
|
||||||
msg_scroll = TRUE;
|
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');
|
msg_putchar('\n');
|
||||||
vim_snprintf((char *)IObuff, IOSIZE, _("Tab page %d"), tabcount++);
|
vim_snprintf((char *)IObuff, IOSIZE, _("Tab page %d"), tabcount++);
|
||||||
msg_outtrans_attr(IObuff, hl_attr(HLF_T));
|
msg_outtrans_attr(IObuff, hl_attr(HLF_T));
|
||||||
out_flush(); /* output one line at a time */
|
out_flush(); /* output one line at a time */
|
||||||
ui_breakcheck();
|
ui_breakcheck();
|
||||||
|
|
||||||
if (tp == curtab)
|
win_T *wp;
|
||||||
|
if (tp == curtab) {
|
||||||
wp = firstwin;
|
wp = firstwin;
|
||||||
else
|
} else {
|
||||||
wp = tp->tp_firstwin;
|
wp = tp->tp_firstwin;
|
||||||
|
}
|
||||||
for (; wp != NULL && !got_int; wp = wp->w_next) {
|
for (; wp != NULL && !got_int; wp = wp->w_next) {
|
||||||
msg_putchar('\n');
|
msg_putchar('\n');
|
||||||
msg_putchar(wp == curwin ? '>' : ' ');
|
msg_putchar(wp == curwin ? '>' : ' ');
|
||||||
|
@@ -548,6 +548,9 @@ EXTERN tabpage_T *first_tabpage;
|
|||||||
EXTERN tabpage_T *curtab;
|
EXTERN tabpage_T *curtab;
|
||||||
EXTERN int redraw_tabline INIT(= FALSE); /* need to redraw tabline */
|
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,
|
* 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.
|
* 'lastbuf' to the last entry and 'curbuf' to the currently active buffer.
|
||||||
|
@@ -7632,7 +7632,6 @@ void unshowmode(int force)
|
|||||||
static void draw_tabline(void)
|
static void draw_tabline(void)
|
||||||
{
|
{
|
||||||
int tabcount = 0;
|
int tabcount = 0;
|
||||||
tabpage_T *tp;
|
|
||||||
int tabwidth;
|
int tabwidth;
|
||||||
int col = 0;
|
int col = 0;
|
||||||
int scol = 0;
|
int scol = 0;
|
||||||
@@ -7675,8 +7674,9 @@ static void draw_tabline(void)
|
|||||||
(char_u *)"", OPT_FREE, SID_ERROR);
|
(char_u *)"", OPT_FREE, SID_ERROR);
|
||||||
called_emsg |= save_called_emsg;
|
called_emsg |= save_called_emsg;
|
||||||
} else {
|
} else {
|
||||||
for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
|
FOR_ALL_TABS(tp) {
|
||||||
++tabcount;
|
++tabcount;
|
||||||
|
}
|
||||||
|
|
||||||
tabwidth = (Columns - 1 + tabcount / 2) / tabcount;
|
tabwidth = (Columns - 1 + tabcount / 2) / tabcount;
|
||||||
if (tabwidth < 6)
|
if (tabwidth < 6)
|
||||||
@@ -7685,8 +7685,12 @@ static void draw_tabline(void)
|
|||||||
attr = attr_nosel;
|
attr = attr_nosel;
|
||||||
tabcount = 0;
|
tabcount = 0;
|
||||||
scol = 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;
|
scol = col;
|
||||||
|
|
||||||
if (tp->tp_topframe == topframe)
|
if (tp->tp_topframe == topframe)
|
||||||
|
@@ -2986,14 +2986,14 @@ int make_tabpages(int maxcount)
|
|||||||
/*
|
/*
|
||||||
* Return TRUE when "tpc" points to a valid tab page.
|
* 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_ALL_TABS(tp) {
|
||||||
|
if (tp == tpc) {
|
||||||
for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
|
return true;
|
||||||
if (tp == tpc)
|
}
|
||||||
return TRUE;
|
}
|
||||||
return FALSE;
|
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 *buf_jump_open_tab(buf_T *buf)
|
||||||
{
|
{
|
||||||
win_T *wp;
|
win_T *wp;
|
||||||
tabpage_T *tp;
|
|
||||||
|
|
||||||
/* First try the current tab page. */
|
/* First try the current tab page. */
|
||||||
wp = buf_jump_open_win(buf);
|
wp = buf_jump_open_win(buf);
|
||||||
if (wp != NULL)
|
if (wp != NULL)
|
||||||
return wp;
|
return wp;
|
||||||
|
|
||||||
for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
|
FOR_ALL_TABS(tp) {
|
||||||
if (tp != curtab) {
|
if (tp != curtab) {
|
||||||
for (wp = tp->tp_firstwin; wp != NULL; wp = wp->w_next)
|
for (wp = tp->tp_firstwin; wp != NULL; wp = wp->w_next)
|
||||||
if (wp->w_buffer == buf)
|
if (wp->w_buffer == buf)
|
||||||
@@ -3569,6 +3568,7 @@ win_T *buf_jump_open_tab(buf_T *buf)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return wp;
|
return wp;
|
||||||
}
|
}
|
||||||
@@ -4963,18 +4963,15 @@ int tabline_height(void)
|
|||||||
*/
|
*/
|
||||||
int min_rows(void)
|
int min_rows(void)
|
||||||
{
|
{
|
||||||
int total;
|
|
||||||
tabpage_T *tp;
|
|
||||||
int n;
|
|
||||||
|
|
||||||
if (firstwin == NULL) /* not initialized yet */
|
if (firstwin == NULL) /* not initialized yet */
|
||||||
return MIN_LINES;
|
return MIN_LINES;
|
||||||
|
|
||||||
total = 0;
|
int total = 0;
|
||||||
for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) {
|
FOR_ALL_TABS(tp) {
|
||||||
n = frame_minheight(tp->tp_topframe, NULL);
|
int n = frame_minheight(tp->tp_topframe, NULL);
|
||||||
if (total < n)
|
if (total < n) {
|
||||||
total = n;
|
total = n;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
total += tabline_height();
|
total += tabline_height();
|
||||||
total += 1; /* count the room for the command line */
|
total += 1; /* count the room for the command line */
|
||||||
|
Reference in New Issue
Block a user