diff options
author | James McCoy <jamessan@jamessan.com> | 2017-03-10 16:13:37 -0500 |
---|---|---|
committer | James McCoy <jamessan@jamessan.com> | 2017-03-11 20:32:09 -0500 |
commit | 564e9dc17fd53ab6cb1bc63a55dba2df9538a31f (patch) | |
tree | 40c382cf733ab05a3d6c51dd684253ddce7b2cf9 | |
parent | 5674057e3a5597f792a077d714bd7d32af81bfc8 (diff) | |
download | rneovim-564e9dc17fd53ab6cb1bc63a55dba2df9538a31f.tar.gz rneovim-564e9dc17fd53ab6cb1bc63a55dba2df9538a31f.tar.bz2 rneovim-564e9dc17fd53ab6cb1bc63a55dba2df9538a31f.zip |
vim-patch:7.4.2101
Problem: Looping over windows, buffers and tab pages is inconsistant.
Solution: Use FOR_ALL_ macros everywhere. (Yegappan Lakshmanan)
https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
-rw-r--r-- | src/nvim/ex_cmds.c | 11 | ||||
-rw-r--r-- | src/nvim/ex_docmd.c | 19 | ||||
-rw-r--r-- | src/nvim/fileio.c | 4 | ||||
-rw-r--r-- | src/nvim/globals.h | 1 | ||||
-rw-r--r-- | src/nvim/move.c | 3 | ||||
-rw-r--r-- | src/nvim/normal.c | 3 | ||||
-rw-r--r-- | src/nvim/option.c | 3 | ||||
-rw-r--r-- | src/nvim/popupmnu.c | 7 | ||||
-rw-r--r-- | src/nvim/version.c | 2 | ||||
-rw-r--r-- | src/nvim/window.c | 33 |
10 files changed, 51 insertions, 35 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 159e027793..54459792aa 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -4365,10 +4365,15 @@ void ex_help(exarg_T *eap) ) { if (cmdmod.tab != 0) wp = NULL; - else - for (wp = firstwin; wp != NULL; wp = wp->w_next) - if (wp->w_buffer != NULL && wp->w_buffer->b_help) + else { + wp = NULL; + FOR_ALL_WINDOWS_IN_TAB(wp2, curtab) { + if (wp2->w_buffer != NULL && wp2->w_buffer->b_help) { + wp = wp2; break; + } + } + } if (wp != NULL && wp->w_buffer->b_nwindows > 0) win_enter(wp, true); else { diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 41cc7d70f7..ba0e8295bf 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -5851,7 +5851,7 @@ static void ex_quit_all(exarg_T *eap) */ static void ex_close(exarg_T *eap) { - win_T *win; + win_T *win = NULL; int winnr = 0; if (cmdwin_type != 0) cmdwin_result = Ctrl_C; @@ -5859,10 +5859,12 @@ static void ex_close(exarg_T *eap) if (eap->addr_count == 0) ex_win_close(eap->forceit, curwin, NULL); else { - for (win = firstwin; win != NULL; win = win->w_next) { + FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { winnr++; - if (winnr == eap->line2) + if (winnr == eap->line2) { + win = wp; break; + } } if (win == NULL) win = lastwin; @@ -6074,12 +6076,14 @@ static void ex_hide(exarg_T *eap) win_close(curwin, FALSE); /* don't free buffer */ else { int winnr = 0; - win_T *win; + win_T *win = NULL; - for (win = firstwin; win != NULL; win = win->w_next) { + FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { winnr++; - if (winnr == eap->line2) + if (winnr == eap->line2) { + win = wp; break; + } } if (win == NULL) win = lastwin; @@ -6846,7 +6850,8 @@ static void ex_syncbind(exarg_T *eap) /* * Set all scrollbind windows to the same topline. */ - for (curwin = firstwin; curwin; curwin = curwin->w_next) { + FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { + curwin = wp; if (curwin->w_p_scb) { curbuf = curwin->w_buffer; y = topline - curwin->w_topline; diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 4ea5121a91..f8b5a11642 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -4733,7 +4733,6 @@ check_timestamps ( int focus /* called for GUI focus event */ ) { - buf_T *buf; int didit = 0; int n; @@ -4758,7 +4757,7 @@ check_timestamps ( ++no_wait_return; did_check_timestamps = TRUE; already_warned = FALSE; - for (buf = firstbuf; buf != NULL; ) { + FOR_ALL_BUFFERS(buf) { /* Only check buffers in a window. */ if (buf->b_nwindows > 0) { bufref_T bufref; @@ -4773,7 +4772,6 @@ check_timestamps ( continue; } } - buf = buf->b_next; } --no_wait_return; need_check_timestamps = FALSE; diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 07ea045c13..f8c7c9d330 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -556,7 +556,6 @@ EXTERN win_T *prevwin INIT(= NULL); /* previous window */ FOR_ALL_TABS(tp) \ FOR_ALL_WINDOWS_IN_TAB(wp, tp) -# define FOR_ALL_WINDOWS(wp) for (wp = firstwin; wp != NULL; wp = wp->w_next) # define FOR_ALL_WINDOWS_IN_TAB(wp, tp) \ for (win_T *wp = ((tp) == curtab) \ ? firstwin : (tp)->tp_firstwin; wp != NULL; wp = wp->w_next) diff --git a/src/nvim/move.c b/src/nvim/move.c index bb6c032db1..4c1b8a8411 100644 --- a/src/nvim/move.c +++ b/src/nvim/move.c @@ -2137,7 +2137,8 @@ void do_check_cursorbind(void) * loop through the cursorbound windows */ VIsual_select = VIsual_active = 0; - for (curwin = firstwin; curwin; curwin = curwin->w_next) { + FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { + curwin = wp; curbuf = curwin->w_buffer; /* skip original window and windows with 'noscrollbind' */ if (curwin != old_curwin && curwin->w_p_crb) { diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 38507486fd..ee3c3f9f11 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -3512,7 +3512,8 @@ void check_scrollbind(linenr_T topline_diff, long leftcol_diff) * loop through the scrollbound windows and scroll accordingly */ VIsual_select = VIsual_active = 0; - for (curwin = firstwin; curwin; curwin = curwin->w_next) { + FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { + curwin = wp; curbuf = curwin->w_buffer; /* skip original window and windows with 'noscrollbind' */ if (curwin == old_curwin || !curwin->w_p_scb) { diff --git a/src/nvim/option.c b/src/nvim/option.c index 322be8aaa0..ba0a501c4a 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -3623,7 +3623,8 @@ set_bool_option ( char_u hash[UNDO_HASH_SIZE]; buf_T *save_curbuf = curbuf; - for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next) { + FOR_ALL_BUFFERS(bp) { + curbuf = bp; /* When 'undofile' is set globally: for every buffer, otherwise * only for the current buffer: Try to read in the undofile, * if one exists, the buffer wasn't changed and the buffer was diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c index 89180f76de..ea00afbd86 100644 --- a/src/nvim/popupmnu.c +++ b/src/nvim/popupmnu.c @@ -73,7 +73,6 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed) int above_row; int below_row; int redo_count = 0; - win_T *pvwin; if (!pum_is_visible) { // To keep the code simple, we only allow changing the @@ -126,8 +125,10 @@ redo: kind_width = 0; extra_width = 0; - FOR_ALL_WINDOWS(pvwin) { - if (pvwin->w_p_pvw) { + win_T *pvwin = NULL; + FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { + if (wp->w_p_pvw) { + pvwin = wp; break; } } diff --git a/src/nvim/version.c b/src/nvim/version.c index 9197be5fd8..d99971b70d 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -339,7 +339,7 @@ static int included_patches[] = { // 2104, 2103, // 2102 NA - // 2101, + 2101, 2100, 2099, 2098, diff --git a/src/nvim/window.c b/src/nvim/window.c index 73a60b2e04..00baa23306 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -161,9 +161,13 @@ newwindow: /* cursor to preview window */ case 'P': - for (wp = firstwin; wp != NULL; wp = wp->w_next) - if (wp->w_p_pvw) + wp = NULL; + FOR_ALL_WINDOWS_IN_TAB(wp2, curtab) { + if (wp2->w_p_pvw) { + wp = wp2; break; + } + } if (wp == NULL) EMSG(_("E441: There is no preview window")); else @@ -3366,9 +3370,13 @@ void tabpage_move(int nr) if (curtab == first_tabpage) first_tabpage = curtab->tp_next; else { - for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) - if (tp->tp_next == curtab) + tp = NULL; + FOR_ALL_TABS(tp2) { + if (tp2->tp_next == curtab) { + tp = tp2; break; + } + } if (tp == NULL) /* "cannot happen" */ return; tp->tp_next = curtab->tp_next; @@ -5753,10 +5761,11 @@ int win_getid(typval_T *argvars) if (argvars[1].v_type == VAR_UNKNOWN) { wp = firstwin; } else { - tabpage_T *tp; + tabpage_T *tp = NULL; int tabnr = get_tv_number(&argvars[1]); - for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) { + FOR_ALL_TABS(tp2) { if (--tabnr == 0) { + tp = tp2; break; } } @@ -5833,11 +5842,10 @@ win_T * win_id2wp(typval_T *argvars) int win_id2win(typval_T *argvars) { - win_T *wp; int nr = 1; int id = get_tv_number(&argvars[0]); - for (wp = firstwin; wp != NULL; wp = wp->w_next) { + FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { if (wp->handle == id) { return nr; } @@ -5850,12 +5858,9 @@ void win_findbuf(typval_T *argvars, list_T *list) { int bufnr = get_tv_number(&argvars[0]); - for (tabpage_T *tp = first_tabpage; tp != NULL; tp = tp->tp_next) { - for (win_T *wp = tp == curtab ? firstwin : tp->tp_firstwin; - wp != NULL; wp = wp->w_next) { - if (wp->w_buffer->b_fnum == bufnr) { - list_append_number(list, wp->handle); - } + FOR_ALL_TAB_WINDOWS(tp, wp) { + if (wp->w_buffer->b_fnum == bufnr) { + list_append_number(list, wp->handle); } } } |