aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/window.c
diff options
context:
space:
mode:
authorWayne Rowcliffe <war1025@gmail.com>2014-08-23 12:03:14 -0500
committerWayne Rowcliffe <war1025@gmail.com>2014-09-22 09:31:09 -0500
commit683bc797a0d427d818f69dd4772e149cf94e6b12 (patch)
tree8bc73873f033b5a37696168c0ddc165869822770 /src/nvim/window.c
parentb4ec6c1a4bacd6eaef958e242310ffaee94805dd (diff)
downloadrneovim-683bc797a0d427d818f69dd4772e149cf94e6b12.tar.gz
rneovim-683bc797a0d427d818f69dd4772e149cf94e6b12.tar.bz2
rneovim-683bc797a0d427d818f69dd4772e149cf94e6b12.zip
FOR_ALL_WINDOWS_IN_TAB and local variables in FOR_ALL_TAB_WINDOWS
Diffstat (limited to 'src/nvim/window.c')
-rw-r--r--src/nvim/window.c94
1 files changed, 53 insertions, 41 deletions
diff --git a/src/nvim/window.c b/src/nvim/window.c
index 6af2087076..ebce53cdf4 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -1674,13 +1674,12 @@ close_windows (
int keep_curwin /* don't close "curwin" */
)
{
- win_T *wp;
tabpage_T *tp, *nexttp;
int h = tabline_height();
++RedrawingDisabled;
- for (wp = firstwin; wp != NULL && lastwin != firstwin; ) {
+ for (win_T *wp = firstwin; wp != NULL && lastwin != firstwin; ) {
if (wp->w_buffer == buf && (!keep_curwin || wp != curwin)
&& !(wp->w_closing || wp->w_buffer->b_closing)
) {
@@ -1695,8 +1694,8 @@ close_windows (
/* Also check windows in other tab pages. */
for (tp = first_tabpage; tp != NULL; tp = nexttp) {
nexttp = tp->tp_next;
- if (tp != curtab)
- for (wp = tp->tp_firstwin; wp != NULL; wp = wp->w_next)
+ if (tp != curtab) {
+ FOR_ALL_WINDOWS_IN_TAB(wp, tp) {
if (wp->w_buffer == buf
&& !(wp->w_closing || wp->w_buffer->b_closing)
) {
@@ -1707,6 +1706,8 @@ close_windows (
nexttp = first_tabpage;
break;
}
+ }
+ }
}
--RedrawingDisabled;
@@ -1963,7 +1964,6 @@ int win_close(win_T *win, int free_buf)
*/
void win_close_othertab(win_T *win, int free_buf, tabpage_T *tp)
{
- win_T *wp;
int dir;
tabpage_T *ptp = NULL;
int free_tp = FALSE;
@@ -1982,10 +1982,18 @@ void win_close_othertab(win_T *win, int free_buf, tabpage_T *tp)
return;
/* Autocommands may have closed the window already. */
- for (wp = tp->tp_firstwin; wp != NULL && wp != win; wp = wp->w_next)
- ;
- if (wp == NULL)
- return;
+ {
+ bool found_window = false;
+ FOR_ALL_WINDOWS_IN_TAB(wp, tp) {
+ if (wp == win) {
+ found_window = true;
+ break;
+ }
+ }
+ if (!found_window) {
+ return;
+ }
+ }
/* When closing the last window in a tab page remove the tab page. */
if (tp->tp_firstwin == tp->tp_lastwin) {
@@ -3285,14 +3293,11 @@ void win_goto(win_T *wp)
*/
tabpage_T *win_find_tabpage(win_T *win)
{
- win_T *wp;
- tabpage_T *tp;
-
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
- for (wp = (tp == curtab ? firstwin : tp->tp_firstwin);
- wp != NULL; wp = wp->w_next)
- if (wp == win)
- return tp;
+ FOR_ALL_TAB_WINDOWS(tp, wp) {
+ if (wp == win) {
+ return tp;
+ }
+ }
return NULL;
}
@@ -3549,28 +3554,36 @@ win_T *buf_jump_open_win(buf_T *buf)
*/
win_T *buf_jump_open_tab(buf_T *buf)
{
- win_T *wp;
- /* First try the current tab page. */
- wp = buf_jump_open_win(buf);
- if (wp != NULL)
- return wp;
+ // First try the current tab page.
+ {
+ win_T *wp = buf_jump_open_win(buf);
+ if (wp != NULL)
+ return wp;
+ }
FOR_ALL_TABS(tp) {
+ // Skip the current tab since we already checked it.
if (tp != curtab) {
- for (wp = tp->tp_firstwin; wp != NULL; wp = wp->w_next)
- if (wp->w_buffer == buf)
- break;
- if (wp != NULL) {
- goto_tabpage_win(tp, wp);
- if (curwin != wp)
- wp = NULL; /* something went wrong */
- break;
+ FOR_ALL_WINDOWS_IN_TAB(wp, tp) {
+ if (wp->w_buffer == buf) {
+ goto_tabpage_win(tp, wp);
+
+ // If we the current window didn't switch,
+ // something went wrong.
+ if (curwin != wp) {
+ wp = NULL;
+ }
+
+ // Return the window we switched to.
+ return wp;
+ }
}
}
}
- return wp;
+ // If we made it this far, we didn't find the buffer.
+ return NULL;
}
/*
@@ -5011,16 +5024,15 @@ int only_one_window(void)
*/
void check_lnums(int do_curwin)
{
- win_T *wp;
-
- tabpage_T *tp;
-
- FOR_ALL_TAB_WINDOWS(tp, wp)
- if ((do_curwin || wp != curwin) && wp->w_buffer == curbuf) {
- if (wp->w_cursor.lnum > curbuf->b_ml.ml_line_count)
- wp->w_cursor.lnum = curbuf->b_ml.ml_line_count;
- if (wp->w_topline > curbuf->b_ml.ml_line_count)
- wp->w_topline = curbuf->b_ml.ml_line_count;
+ FOR_ALL_TAB_WINDOWS(tp, wp) {
+ if ((do_curwin || wp != curwin) && wp->w_buffer == curbuf) {
+ if (wp->w_cursor.lnum > curbuf->b_ml.ml_line_count) {
+ wp->w_cursor.lnum = curbuf->b_ml.ml_line_count;
+ }
+ if (wp->w_topline > curbuf->b_ml.ml_line_count) {
+ wp->w_topline = curbuf->b_ml.ml_line_count;
+ }
+ }
}
}