comparison src/buffer.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 123d3c102035
children e84e45786691
comparison
equal deleted inserted replaced
9648:227649fd4301 9649:fd9727ae3c49
103 /* 103 /*
104 * There MUST be a memfile, otherwise we can't do anything 104 * There MUST be a memfile, otherwise we can't do anything
105 * If we can't create one for the current buffer, take another buffer 105 * If we can't create one for the current buffer, take another buffer
106 */ 106 */
107 close_buffer(NULL, curbuf, 0, FALSE); 107 close_buffer(NULL, curbuf, 0, FALSE);
108 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next) 108 FOR_ALL_BUFFERS(curbuf)
109 if (curbuf->b_ml.ml_mfp != NULL) 109 if (curbuf->b_ml.ml_mfp != NULL)
110 break; 110 break;
111 /* 111 /*
112 * if there is no memfile at all, exit 112 * if there is no memfile at all, exit
113 * This is OK, since there are no changes to lose. 113 * This is OK, since there are no changes to lose.
1282 1282
1283 /* 1283 /*
1284 * If deleting the last (listed) buffer, make it empty. 1284 * If deleting the last (listed) buffer, make it empty.
1285 * The last (listed) buffer cannot be unloaded. 1285 * The last (listed) buffer cannot be unloaded.
1286 */ 1286 */
1287 for (bp = firstbuf; bp != NULL; bp = bp->b_next) 1287 FOR_ALL_BUFFERS(bp)
1288 if (bp->b_p_bl && bp != buf) 1288 if (bp->b_p_bl && bp != buf)
1289 break; 1289 break;
1290 if (bp == NULL && buf == curbuf) 1290 if (bp == NULL && buf == curbuf)
1291 return empty_curbuf(TRUE, forceit, action); 1291 return empty_curbuf(TRUE, forceit, action);
1292 1292
1408 } 1408 }
1409 if (buf == NULL) /* No loaded buffer, use unloaded one */ 1409 if (buf == NULL) /* No loaded buffer, use unloaded one */
1410 buf = bp; 1410 buf = bp;
1411 if (buf == NULL) /* No loaded buffer, find listed one */ 1411 if (buf == NULL) /* No loaded buffer, find listed one */
1412 { 1412 {
1413 for (buf = firstbuf; buf != NULL; buf = buf->b_next) 1413 FOR_ALL_BUFFERS(buf)
1414 if (buf->b_p_bl && buf != curbuf) 1414 if (buf->b_p_bl && buf != curbuf)
1415 break; 1415 break;
1416 } 1416 }
1417 if (buf == NULL) /* Still no buffer, just take one */ 1417 if (buf == NULL) /* Still no buffer, just take one */
1418 { 1418 {
2404 /* Ignore the match if the buffer is not open in 2404 /* Ignore the match if the buffer is not open in
2405 * the current tab. */ 2405 * the current tab. */
2406 #ifdef FEAT_WINDOWS 2406 #ifdef FEAT_WINDOWS
2407 win_T *wp; 2407 win_T *wp;
2408 2408
2409 for (wp = firstwin; wp != NULL; wp = wp->w_next) 2409 FOR_ALL_WINDOWS(wp)
2410 if (wp->w_buffer == buf) 2410 if (wp->w_buffer == buf)
2411 break; 2411 break;
2412 if (wp == NULL) 2412 if (wp == NULL)
2413 continue; 2413 continue;
2414 #else 2414 #else
2506 * round == 2: Build the array to keep the matches. 2506 * round == 2: Build the array to keep the matches.
2507 */ 2507 */
2508 for (round = 1; round <= 2; ++round) 2508 for (round = 1; round <= 2; ++round)
2509 { 2509 {
2510 count = 0; 2510 count = 0;
2511 for (buf = firstbuf; buf != NULL; buf = buf->b_next) 2511 FOR_ALL_BUFFERS(buf)
2512 { 2512 {
2513 if (!buf->b_p_bl) /* skip unlisted buffers */ 2513 if (!buf->b_p_bl) /* skip unlisted buffers */
2514 continue; 2514 continue;
2515 p = buflist_match(&regmatch, buf, p_wic); 2515 p = buflist_match(&regmatch, buf, p_wic);
2516 if (p != NULL) 2516 if (p != NULL)
2732 { 2732 {
2733 win_T *wp; 2733 win_T *wp;
2734 2734
2735 if (wip->wi_opt.wo_diff) 2735 if (wip->wi_opt.wo_diff)
2736 { 2736 {
2737 for (wp = firstwin; wp != NULL; wp = wp->w_next) 2737 FOR_ALL_WINDOWS(wp)
2738 /* return FALSE when it's a window in the current tab page, thus 2738 /* return FALSE when it's a window in the current tab page, thus
2739 * the buffer was in diff mode here */ 2739 * the buffer was in diff mode here */
2740 if (wip->wi_win == wp) 2740 if (wip->wi_win == wp)
2741 return FALSE; 2741 return FALSE;
2742 return TRUE; 2742 return TRUE;
3151 void 3151 void
3152 buflist_slash_adjust(void) 3152 buflist_slash_adjust(void)
3153 { 3153 {
3154 buf_T *bp; 3154 buf_T *bp;
3155 3155
3156 for (bp = firstbuf; bp != NULL; bp = bp->b_next) 3156 FOR_ALL_BUFFERS(bp)
3157 { 3157 {
3158 if (bp->b_ffname != NULL) 3158 if (bp->b_ffname != NULL)
3159 slash_adjust(bp->b_ffname); 3159 slash_adjust(bp->b_ffname);
3160 if (bp->b_sfname != NULL) 3160 if (bp->b_sfname != NULL)
3161 slash_adjust(bp->b_sfname); 3161 slash_adjust(bp->b_sfname);
5081 } 5081 }
5082 else 5082 else
5083 #endif 5083 #endif
5084 { 5084 {
5085 /* Check if this buffer already has a window */ 5085 /* Check if this buffer already has a window */
5086 for (wp = firstwin; wp != NULL; wp = wp->w_next) 5086 FOR_ALL_WINDOWS(wp)
5087 if (wp->w_buffer == buf) 5087 if (wp->w_buffer == buf)
5088 break; 5088 break;
5089 /* If the buffer already has a window, move it */ 5089 /* If the buffer already has a window, move it */
5090 if (wp != NULL) 5090 if (wp != NULL)
5091 win_move_after(wp, curwin); 5091 win_move_after(wp, curwin);
5459 #else 5459 #else
5460 set_last_cursor(curwin); 5460 set_last_cursor(curwin);
5461 #endif 5461 #endif
5462 5462
5463 fputs(_("\n# Buffer list:\n"), fp); 5463 fputs(_("\n# Buffer list:\n"), fp);
5464 for (buf = firstbuf; buf != NULL ; buf = buf->b_next) 5464 FOR_ALL_BUFFERS(buf)
5465 { 5465 {
5466 if (buf->b_fname == NULL 5466 if (buf->b_fname == NULL
5467 || !buf->b_p_bl 5467 || !buf->b_p_bl
5468 #ifdef FEAT_QUICKFIX 5468 #ifdef FEAT_QUICKFIX
5469 || bt_quickfix(buf) 5469 || bt_quickfix(buf)
5845 void 5845 void
5846 buf_delete_all_signs(void) 5846 buf_delete_all_signs(void)
5847 { 5847 {
5848 buf_T *buf; /* buffer we are checking for signs */ 5848 buf_T *buf; /* buffer we are checking for signs */
5849 5849
5850 for (buf = firstbuf; buf != NULL; buf = buf->b_next) 5850 FOR_ALL_BUFFERS(buf)
5851 if (buf->b_signlist != NULL) 5851 if (buf->b_signlist != NULL)
5852 buf_delete_signs(buf); 5852 buf_delete_signs(buf);
5853 } 5853 }
5854 5854
5855 /* 5855 /*