Mercurial > vim
comparison src/window.c @ 9649:fd9727ae3c49 v7.4.2101
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jul 24 22:04:11 2016 +0200
patch 7.4.2101
Problem: Looping over windows, buffers and tab pages is inconsistant.
Solution: Use FOR_ALL_ macros everywhere. (Yegappan Lakshmanan)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 24 Jul 2016 22:15:07 +0200 |
parents | 42a8a81decdf |
children | 3e96d9ed2ca1 |
comparison
equal
deleted
inserted
replaced
9648:227649fd4301 | 9649:fd9727ae3c49 |
---|---|
207 do_cmdline_cmd((char_u *)"pclose"); | 207 do_cmdline_cmd((char_u *)"pclose"); |
208 break; | 208 break; |
209 | 209 |
210 /* cursor to preview window */ | 210 /* cursor to preview window */ |
211 case 'P': | 211 case 'P': |
212 for (wp = firstwin; wp != NULL; wp = wp->w_next) | 212 FOR_ALL_WINDOWS(wp) |
213 if (wp->w_p_pvw) | 213 if (wp->w_p_pvw) |
214 break; | 214 break; |
215 if (wp == NULL) | 215 if (wp == NULL) |
216 EMSG(_("E441: There is no preview window")); | 216 EMSG(_("E441: There is no preview window")); |
217 else | 217 else |
1365 { | 1365 { |
1366 win_T *wp; | 1366 win_T *wp; |
1367 | 1367 |
1368 if (win == NULL) | 1368 if (win == NULL) |
1369 return FALSE; | 1369 return FALSE; |
1370 for (wp = firstwin; wp != NULL; wp = wp->w_next) | 1370 FOR_ALL_WINDOWS(wp) |
1371 if (wp == win) | 1371 if (wp == win) |
1372 return TRUE; | 1372 return TRUE; |
1373 return FALSE; | 1373 return FALSE; |
1374 } | 1374 } |
1375 | 1375 |
1380 win_count(void) | 1380 win_count(void) |
1381 { | 1381 { |
1382 win_T *wp; | 1382 win_T *wp; |
1383 int count = 0; | 1383 int count = 0; |
1384 | 1384 |
1385 for (wp = firstwin; wp != NULL; wp = wp->w_next) | 1385 FOR_ALL_WINDOWS(wp) |
1386 ++count; | 1386 ++count; |
1387 return count; | 1387 return count; |
1388 } | 1388 } |
1389 | 1389 |
1390 /* | 1390 /* |
3710 int | 3710 int |
3711 valid_tabpage(tabpage_T *tpc) | 3711 valid_tabpage(tabpage_T *tpc) |
3712 { | 3712 { |
3713 tabpage_T *tp; | 3713 tabpage_T *tp; |
3714 | 3714 |
3715 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) | 3715 FOR_ALL_TABPAGES(tp) |
3716 if (tp == tpc) | 3716 if (tp == tpc) |
3717 return TRUE; | 3717 return TRUE; |
3718 return FALSE; | 3718 return FALSE; |
3719 } | 3719 } |
3720 | 3720 |
4010 /* Remove the current tab page from the list of tab pages. */ | 4010 /* Remove the current tab page from the list of tab pages. */ |
4011 if (curtab == first_tabpage) | 4011 if (curtab == first_tabpage) |
4012 first_tabpage = curtab->tp_next; | 4012 first_tabpage = curtab->tp_next; |
4013 else | 4013 else |
4014 { | 4014 { |
4015 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) | 4015 FOR_ALL_TABPAGES(tp) |
4016 if (tp->tp_next == curtab) | 4016 if (tp->tp_next == curtab) |
4017 break; | 4017 break; |
4018 if (tp == NULL) /* "cannot happen" */ | 4018 if (tp == NULL) /* "cannot happen" */ |
4019 return; | 4019 return; |
4020 tp->tp_next = curtab->tp_next; | 4020 tp->tp_next = curtab->tp_next; |
4089 win_find_nr(int winnr) | 4089 win_find_nr(int winnr) |
4090 { | 4090 { |
4091 win_T *wp; | 4091 win_T *wp; |
4092 | 4092 |
4093 # ifdef FEAT_WINDOWS | 4093 # ifdef FEAT_WINDOWS |
4094 for (wp = firstwin; wp != NULL; wp = wp->w_next) | 4094 FOR_ALL_WINDOWS(wp) |
4095 if (--winnr == 0) | 4095 if (--winnr == 0) |
4096 break; | 4096 break; |
4097 return wp; | 4097 return wp; |
4098 # else | 4098 # else |
4099 return curwin; | 4099 return curwin; |
4110 win_find_tabpage(win_T *win) | 4110 win_find_tabpage(win_T *win) |
4111 { | 4111 { |
4112 win_T *wp; | 4112 win_T *wp; |
4113 tabpage_T *tp; | 4113 tabpage_T *tp; |
4114 | 4114 |
4115 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) | 4115 FOR_ALL_TAB_WINDOWS(tp, wp) |
4116 for (wp = (tp == curtab ? firstwin : tp->tp_firstwin); | |
4117 wp != NULL; wp = wp->w_next) | |
4118 if (wp == win) | 4116 if (wp == win) |
4119 return tp; | 4117 return tp; |
4120 return NULL; | 4118 return NULL; |
4121 } | 4119 } |
4122 #endif | 4120 #endif |
4402 | 4400 |
4403 if (curwin->w_buffer == buf) | 4401 if (curwin->w_buffer == buf) |
4404 wp = curwin; | 4402 wp = curwin; |
4405 # ifdef FEAT_WINDOWS | 4403 # ifdef FEAT_WINDOWS |
4406 else | 4404 else |
4407 for (wp = firstwin; wp != NULL; wp = wp->w_next) | 4405 FOR_ALL_WINDOWS(wp) |
4408 if (wp->w_buffer == buf) | 4406 if (wp->w_buffer == buf) |
4409 break; | 4407 break; |
4410 if (wp != NULL) | 4408 if (wp != NULL) |
4411 win_enter(wp, FALSE); | 4409 win_enter(wp, FALSE); |
4412 # endif | 4410 # endif |
4426 tabpage_T *tp; | 4424 tabpage_T *tp; |
4427 | 4425 |
4428 if (wp != NULL) | 4426 if (wp != NULL) |
4429 return wp; | 4427 return wp; |
4430 | 4428 |
4431 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) | 4429 FOR_ALL_TABPAGES(tp) |
4432 if (tp != curtab) | 4430 if (tp != curtab) |
4433 { | 4431 { |
4434 for (wp = tp->tp_firstwin; wp != NULL; wp = wp->w_next) | 4432 for (wp = tp->tp_firstwin; wp != NULL; wp = wp->w_next) |
4435 if (wp->w_buffer == buf) | 4433 if (wp->w_buffer == buf) |
4436 break; | 4434 break; |
4605 { | 4603 { |
4606 tabpage_T *ttp; | 4604 tabpage_T *ttp; |
4607 | 4605 |
4608 if (prevwin == wp) | 4606 if (prevwin == wp) |
4609 prevwin = NULL; | 4607 prevwin = NULL; |
4610 for (ttp = first_tabpage; ttp != NULL; ttp = ttp->tp_next) | 4608 FOR_ALL_TABPAGES(ttp) |
4611 if (ttp->tp_prevwin == wp) | 4609 if (ttp->tp_prevwin == wp) |
4612 ttp->tp_prevwin = NULL; | 4610 ttp->tp_prevwin = NULL; |
4613 } | 4611 } |
4614 win_free_lsize(wp); | 4612 win_free_lsize(wp); |
4615 | 4613 |
4618 | 4616 |
4619 vim_free(wp->w_localdir); | 4617 vim_free(wp->w_localdir); |
4620 | 4618 |
4621 /* Remove the window from the b_wininfo lists, it may happen that the | 4619 /* Remove the window from the b_wininfo lists, it may happen that the |
4622 * freed memory is re-used for another window. */ | 4620 * freed memory is re-used for another window. */ |
4623 for (buf = firstbuf; buf != NULL; buf = buf->b_next) | 4621 FOR_ALL_BUFFERS(buf) |
4624 for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next) | 4622 for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next) |
4625 if (wip->wi_win == wp) | 4623 if (wip->wi_win == wp) |
4626 wip->wi_win = NULL; | 4624 wip->wi_win = NULL; |
4627 | 4625 |
4628 #ifdef FEAT_SEARCH_EXTRA | 4626 #ifdef FEAT_SEARCH_EXTRA |
4861 { | 4859 { |
4862 win_T *wp; | 4860 win_T *wp; |
4863 | 4861 |
4864 ga_init2(gap, (int)sizeof(int), 1); | 4862 ga_init2(gap, (int)sizeof(int), 1); |
4865 if (ga_grow(gap, win_count() * 2) == OK) | 4863 if (ga_grow(gap, win_count() * 2) == OK) |
4866 for (wp = firstwin; wp != NULL; wp = wp->w_next) | 4864 FOR_ALL_WINDOWS(wp) |
4867 { | 4865 { |
4868 ((int *)gap->ga_data)[gap->ga_len++] = | 4866 ((int *)gap->ga_data)[gap->ga_len++] = |
4869 wp->w_width + wp->w_vsep_width; | 4867 wp->w_width + wp->w_vsep_width; |
4870 ((int *)gap->ga_data)[gap->ga_len++] = wp->w_height; | 4868 ((int *)gap->ga_data)[gap->ga_len++] = wp->w_height; |
4871 } | 4869 } |
4886 /* The order matters, because frames contain other frames, but it's | 4884 /* The order matters, because frames contain other frames, but it's |
4887 * difficult to get right. The easy way out is to do it twice. */ | 4885 * difficult to get right. The easy way out is to do it twice. */ |
4888 for (j = 0; j < 2; ++j) | 4886 for (j = 0; j < 2; ++j) |
4889 { | 4887 { |
4890 i = 0; | 4888 i = 0; |
4891 for (wp = firstwin; wp != NULL; wp = wp->w_next) | 4889 FOR_ALL_WINDOWS(wp) |
4892 { | 4890 { |
4893 frame_setwidth(wp->w_frame, ((int *)gap->ga_data)[i++]); | 4891 frame_setwidth(wp->w_frame, ((int *)gap->ga_data)[i++]); |
4894 win_setheight_win(((int *)gap->ga_data)[i++], wp); | 4892 win_setheight_win(((int *)gap->ga_data)[i++], wp); |
4895 } | 4893 } |
4896 } | 4894 } |
5382 /* loop until there is a 'winminheight' that is possible */ | 5380 /* loop until there is a 'winminheight' that is possible */ |
5383 while (p_wmh > 0) | 5381 while (p_wmh > 0) |
5384 { | 5382 { |
5385 /* TODO: handle vertical splits */ | 5383 /* TODO: handle vertical splits */ |
5386 room = -p_wh; | 5384 room = -p_wh; |
5387 for (wp = firstwin; wp != NULL; wp = wp->w_next) | 5385 FOR_ALL_WINDOWS(wp) |
5388 room += wp->w_height - p_wmh; | 5386 room += wp->w_height - p_wmh; |
5389 if (room >= 0) | 5387 if (room >= 0) |
5390 break; | 5388 break; |
5391 --p_wmh; | 5389 --p_wmh; |
5392 if (first) | 5390 if (first) |
6342 if (firstwin == NULL) /* not initialized yet */ | 6340 if (firstwin == NULL) /* not initialized yet */ |
6343 return MIN_LINES; | 6341 return MIN_LINES; |
6344 | 6342 |
6345 #ifdef FEAT_WINDOWS | 6343 #ifdef FEAT_WINDOWS |
6346 total = 0; | 6344 total = 0; |
6347 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) | 6345 FOR_ALL_TABPAGES(tp) |
6348 { | 6346 { |
6349 n = frame_minheight(tp->tp_topframe, NULL); | 6347 n = frame_minheight(tp->tp_topframe, NULL); |
6350 if (total < n) | 6348 if (total < n) |
6351 total = n; | 6349 total = n; |
6352 } | 6350 } |
6372 | 6370 |
6373 /* If there is another tab page there always is another window. */ | 6371 /* If there is another tab page there always is another window. */ |
6374 if (first_tabpage->tp_next != NULL) | 6372 if (first_tabpage->tp_next != NULL) |
6375 return FALSE; | 6373 return FALSE; |
6376 | 6374 |
6377 for (wp = firstwin; wp != NULL; wp = wp->w_next) | 6375 FOR_ALL_WINDOWS(wp) |
6378 if (wp->w_buffer != NULL | 6376 if (wp->w_buffer != NULL |
6379 && (!((wp->w_buffer->b_help && !curbuf->b_help) | 6377 && (!((wp->w_buffer->b_help && !curbuf->b_help) |
6380 # ifdef FEAT_QUICKFIX | 6378 # ifdef FEAT_QUICKFIX |
6381 || wp->w_p_pvw | 6379 || wp->w_p_pvw |
6382 # endif | 6380 # endif |
7089 else | 7087 else |
7090 { | 7088 { |
7091 tabpage_T *tp; | 7089 tabpage_T *tp; |
7092 int tabnr = get_tv_number(&argvars[1]); | 7090 int tabnr = get_tv_number(&argvars[1]); |
7093 | 7091 |
7094 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) | 7092 FOR_ALL_TABPAGES(tp) |
7095 if (--tabnr == 0) | 7093 if (--tabnr == 0) |
7096 break; | 7094 break; |
7097 if (tp == NULL) | 7095 if (tp == NULL) |
7098 return -1; | 7096 return -1; |
7099 wp = tp->tp_firstwin; | 7097 wp = tp->tp_firstwin; |
7110 { | 7108 { |
7111 win_T *wp; | 7109 win_T *wp; |
7112 tabpage_T *tp; | 7110 tabpage_T *tp; |
7113 int id = get_tv_number(&argvars[0]); | 7111 int id = get_tv_number(&argvars[0]); |
7114 | 7112 |
7115 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) | 7113 FOR_ALL_TAB_WINDOWS(tp, wp) |
7116 for (wp = tp == curtab ? firstwin : tp->tp_firstwin; | |
7117 wp != NULL; wp = wp->w_next) | |
7118 if (wp->w_id == id) | 7114 if (wp->w_id == id) |
7119 { | 7115 { |
7120 goto_tabpage_win(tp, wp); | 7116 goto_tabpage_win(tp, wp); |
7121 return 1; | 7117 return 1; |
7122 } | 7118 } |
7130 tabpage_T *tp; | 7126 tabpage_T *tp; |
7131 int winnr = 1; | 7127 int winnr = 1; |
7132 int tabnr = 1; | 7128 int tabnr = 1; |
7133 int id = get_tv_number(&argvars[0]); | 7129 int id = get_tv_number(&argvars[0]); |
7134 | 7130 |
7135 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) | 7131 FOR_ALL_TABPAGES(tp) |
7136 { | 7132 { |
7137 for (wp = tp == curtab ? firstwin : tp->tp_firstwin; | 7133 FOR_ALL_WINDOWS_IN_TAB(tp, wp) |
7138 wp != NULL; wp = wp->w_next) | |
7139 { | 7134 { |
7140 if (wp->w_id == id) | 7135 if (wp->w_id == id) |
7141 { | 7136 { |
7142 list_append_number(list, tabnr); | 7137 list_append_number(list, tabnr); |
7143 list_append_number(list, winnr); | 7138 list_append_number(list, winnr); |
7157 { | 7152 { |
7158 win_T *wp; | 7153 win_T *wp; |
7159 int nr = 1; | 7154 int nr = 1; |
7160 int id = get_tv_number(&argvars[0]); | 7155 int id = get_tv_number(&argvars[0]); |
7161 | 7156 |
7162 for (wp = firstwin; wp != NULL; wp = wp->w_next) | 7157 FOR_ALL_WINDOWS(wp) |
7163 { | 7158 { |
7164 if (wp->w_id == id) | 7159 if (wp->w_id == id) |
7165 return nr; | 7160 return nr; |
7166 ++nr; | 7161 ++nr; |
7167 } | 7162 } |
7173 { | 7168 { |
7174 win_T *wp; | 7169 win_T *wp; |
7175 tabpage_T *tp; | 7170 tabpage_T *tp; |
7176 int bufnr = get_tv_number(&argvars[0]); | 7171 int bufnr = get_tv_number(&argvars[0]); |
7177 | 7172 |
7178 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) | 7173 FOR_ALL_TAB_WINDOWS(tp, wp) |
7179 for (wp = tp == curtab ? firstwin : tp->tp_firstwin; | |
7180 wp != NULL; wp = wp->w_next) | |
7181 if (wp->w_buffer->b_fnum == bufnr) | 7174 if (wp->w_buffer->b_fnum == bufnr) |
7182 list_append_number(list, wp->w_id); | 7175 list_append_number(list, wp->w_id); |
7183 } | 7176 } |
7184 | 7177 |
7185 #endif | 7178 #endif |