]> granicus.if.org Git - vim/commitdiff
patch 7.4.2101 v7.4.2101
authorBram Moolenaar <Bram@vim.org>
Sun, 24 Jul 2016 20:04:11 +0000 (22:04 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 24 Jul 2016 20:04:11 +0000 (22:04 +0200)
Problem:    Looping over windows, buffers and tab pages is inconsistant.
Solution:   Use FOR_ALL_ macros everywhere. (Yegappan Lakshmanan)

33 files changed:
src/buffer.c
src/diff.c
src/edit.c
src/eval.c
src/evalfunc.c
src/ex_cmds.c
src/ex_cmds2.c
src/ex_docmd.c
src/fileio.c
src/globals.h
src/gui.c
src/gui_mac.c
src/if_lua.c
src/if_mzsch.c
src/if_perl.xs
src/if_ruby.c
src/if_tcl.c
src/main.c
src/mark.c
src/memfile.c
src/memline.c
src/misc1.c
src/move.c
src/netbeans.c
src/normal.c
src/option.c
src/quickfix.c
src/screen.c
src/spell.c
src/term.c
src/version.c
src/window.c
src/workshop.c

index 8590e2a2e9ca8455c80647071dbb3fadc95056ec..60fb67a23b41ca7998327f16a9dbed457344fa27 100644 (file)
@@ -105,7 +105,7 @@ open_buffer(
         * If we can't create one for the current buffer, take another buffer
         */
        close_buffer(NULL, curbuf, 0, FALSE);
-       for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
+       FOR_ALL_BUFFERS(curbuf)
            if (curbuf->b_ml.ml_mfp != NULL)
                break;
        /*
@@ -1284,7 +1284,7 @@ do_buffer(
         * If deleting the last (listed) buffer, make it empty.
         * The last (listed) buffer cannot be unloaded.
         */
-       for (bp = firstbuf; bp != NULL; bp = bp->b_next)
+       FOR_ALL_BUFFERS(bp)
            if (bp->b_p_bl && bp != buf)
                break;
        if (bp == NULL && buf == curbuf)
@@ -1410,7 +1410,7 @@ do_buffer(
            buf = bp;
        if (buf == NULL)        /* No loaded buffer, find listed one */
        {
-           for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+           FOR_ALL_BUFFERS(buf)
                if (buf->b_p_bl && buf != curbuf)
                    break;
        }
@@ -2406,7 +2406,7 @@ buflist_findpat(
 #ifdef FEAT_WINDOWS
                            win_T       *wp;
 
-                           for (wp = firstwin; wp != NULL; wp = wp->w_next)
+                           FOR_ALL_WINDOWS(wp)
                                if (wp->w_buffer == buf)
                                    break;
                            if (wp == NULL)
@@ -2508,7 +2508,7 @@ ExpandBufnames(
        for (round = 1; round <= 2; ++round)
        {
            count = 0;
-           for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+           FOR_ALL_BUFFERS(buf)
            {
                if (!buf->b_p_bl)       /* skip unlisted buffers */
                    continue;
@@ -2734,7 +2734,7 @@ wininfo_other_tab_diff(wininfo_T *wip)
 
     if (wip->wi_opt.wo_diff)
     {
-       for (wp = firstwin; wp != NULL; wp = wp->w_next)
+       FOR_ALL_WINDOWS(wp)
            /* return FALSE when it's a window in the current tab page, thus
             * the buffer was in diff mode here */
            if (wip->wi_win == wp)
@@ -3153,7 +3153,7 @@ buflist_slash_adjust(void)
 {
     buf_T      *bp;
 
-    for (bp = firstbuf; bp != NULL; bp = bp->b_next)
+    FOR_ALL_BUFFERS(bp)
     {
        if (bp->b_ffname != NULL)
            slash_adjust(bp->b_ffname);
@@ -5083,7 +5083,7 @@ ex_buffer_all(exarg_T *eap)
 #endif
        {
            /* Check if this buffer already has a window */
-           for (wp = firstwin; wp != NULL; wp = wp->w_next)
+           FOR_ALL_WINDOWS(wp)
                if (wp->w_buffer == buf)
                    break;
            /* If the buffer already has a window, move it */
@@ -5461,7 +5461,7 @@ write_viminfo_bufferlist(FILE *fp)
 #endif
 
     fputs(_("\n# Buffer list:\n"), fp);
-    for (buf = firstbuf; buf != NULL ; buf = buf->b_next)
+    FOR_ALL_BUFFERS(buf)
     {
        if (buf->b_fname == NULL
                || !buf->b_p_bl
@@ -5847,7 +5847,7 @@ buf_delete_all_signs(void)
 {
     buf_T      *buf;           /* buffer we are checking for signs */
 
-    for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+    FOR_ALL_BUFFERS(buf)
        if (buf->b_signlist != NULL)
            buf_delete_signs(buf);
 }
index 287f434bee6beeaa4413a8f281574fc068f455c7..35e37d750b6a06e77003558808660774cd1bd186 100644 (file)
@@ -65,7 +65,7 @@ diff_buf_delete(buf_T *buf)
     int                i;
     tabpage_T  *tp;
 
-    for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+    FOR_ALL_TABPAGES(tp)
     {
        i = diff_buf_idx_tp(buf, tp);
        if (i != DB_COUNT)
@@ -92,7 +92,7 @@ diff_buf_adjust(win_T *win)
     {
        /* When there is no window showing a diff for this buffer, remove
         * it from the diffs. */
-       for (wp = firstwin; wp != NULL; wp = wp->w_next)
+       FOR_ALL_WINDOWS(wp)
            if (wp->w_buffer == win->w_buffer && wp->w_p_diff)
                break;
        if (wp == NULL)
@@ -178,7 +178,7 @@ diff_invalidate(buf_T *buf)
     tabpage_T  *tp;
     int                i;
 
-    for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+    FOR_ALL_TABPAGES(tp)
     {
        i = diff_buf_idx_tp(buf, tp);
        if (i != DB_COUNT)
@@ -204,7 +204,7 @@ diff_mark_adjust(
     tabpage_T  *tp;
 
     /* Handle all tab pages that use the current buffer in a diff. */
-    for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+    FOR_ALL_TABPAGES(tp)
     {
        idx = diff_buf_idx_tp(curbuf, tp);
        if (idx != DB_COUNT)
@@ -591,7 +591,7 @@ diff_redraw(
     win_T      *wp;
     int                n;
 
-    for (wp = firstwin; wp != NULL; wp = wp->w_next)
+    FOR_ALL_WINDOWS(wp)
        if (wp->w_p_diff)
        {
            redraw_win_later(wp, SOME_VALID);
@@ -1198,7 +1198,7 @@ ex_diffoff(exarg_T *eap)
     int                diffwin = FALSE;
 #endif
 
-    for (wp = firstwin; wp != NULL; wp = wp->w_next)
+    FOR_ALL_WINDOWS(wp)
     {
        if (eap->forceit ? wp->w_p_diff : wp == curwin)
        {
@@ -1879,7 +1879,7 @@ diffopt_changed(void)
 
     /* If "icase" or "iwhite" was added or removed, need to update the diff. */
     if (diff_flags != diff_flags_new)
-       for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+       FOR_ALL_TABPAGES(tp)
            tp->tp_diff_invalid = TRUE;
 
     diff_flags = diff_flags_new;
@@ -2434,7 +2434,7 @@ diff_fold_update(diff_T *dp, int skip_idx)
     int                i;
     win_T      *wp;
 
-    for (wp = firstwin; wp != NULL; wp = wp->w_next)
+    FOR_ALL_WINDOWS(wp)
        for (i = 0; i < DB_COUNT; ++i)
            if (curtab->tp_diffbuf[i] == wp->w_buffer && i != skip_idx)
                foldUpdate(wp, dp->df_lnum[i],
@@ -2450,7 +2450,7 @@ diff_mode_buf(buf_T *buf)
 {
     tabpage_T  *tp;
 
-    for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+    FOR_ALL_TABPAGES(tp)
        if (diff_buf_idx_tp(buf, tp) != DB_COUNT)
            return TRUE;
     return FALSE;
index 4bce8a30c7200165157e7094bf8d0ceb45b40410..a60d9229adc39065b3aa6992fcbbf0ff9d71f3f3 100644 (file)
@@ -4239,7 +4239,7 @@ ins_compl_get_exp(pos_T *ini)
 
     if (!compl_started)
     {
-       for (ins_buf = firstbuf; ins_buf != NULL; ins_buf = ins_buf->b_next)
+       FOR_ALL_BUFFERS(ins_buf)
            ins_buf->b_scanned = 0;
        found_all = FALSE;
        ins_buf = curbuf;
index 3bc2afdb1f85dca4cd993e704c1694e05a0668b5..6f10756abf40b9814d8337bbf4db5497077eb3e8 100644 (file)
@@ -5253,7 +5253,7 @@ garbage_collect(int testing)
        abort = abort || set_ref_in_ht(&SCRIPT_VARS(i), copyID, NULL);
 
     /* buffer-local variables */
-    for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+    FOR_ALL_BUFFERS(buf)
        abort = abort || set_ref_in_item(&buf->b_bufvar.di_tv, copyID,
                                                                  NULL, NULL);
 
@@ -5269,7 +5269,7 @@ garbage_collect(int testing)
 
 #ifdef FEAT_WINDOWS
     /* tabpage-local variables */
-    for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+    FOR_ALL_TABPAGES(tp)
        abort = abort || set_ref_in_item(&tp->tp_winvar.di_tv, copyID,
                                                                  NULL, NULL);
 #endif
@@ -8303,8 +8303,8 @@ find_win_by_nr(
     if (nr == 0)
        return curwin;
 
-    for (wp = (tp == NULL || tp == curtab) ? firstwin : tp->tp_firstwin;
-                                                 wp != NULL; wp = wp->w_next)
+    FOR_ALL_WINDOWS_IN_TAB(tp, wp)
+    {
        if (nr >= LOWEST_WIN_ID)
        {
            if (wp->w_id == nr)
@@ -8312,6 +8312,7 @@ find_win_by_nr(
        }
        else if (--nr <= 0)
            break;
+    }
     if (nr >= LOWEST_WIN_ID)
        return NULL;
     return wp;
index ec347c11246a3bb45b2677ae4d157dcac4c0583c..ae17038cceb00e3feca29db804588a22af8ca60a 100644 (file)
@@ -1439,7 +1439,7 @@ find_buffer(typval_T *avar)
        {
            /* No full path name match, try a match with a URL or a "nofile"
             * buffer, these don't use the full path. */
-           for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+           FOR_ALL_BUFFERS(buf)
                if (buf->b_fname != NULL
                        && (path_with_url(buf->b_fname)
 #ifdef FEAT_QUICKFIX
@@ -1597,7 +1597,7 @@ buf_win_common(typval_T *argvars, typval_T *rettv, int get_nr)
     ++emsg_off;
     buf = get_buf_tv(&argvars[0], TRUE);
 #ifdef FEAT_WINDOWS
-    for (wp = firstwin; wp; wp = wp->w_next)
+    FOR_ALL_WINDOWS(wp)
     {
        ++winnr;
        if (wp->w_buffer == buf)
@@ -6383,7 +6383,7 @@ f_last_buffer_nr(typval_T *argvars UNUSED, typval_T *rettv)
     int                n = 0;
     buf_T      *buf;
 
-    for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+    FOR_ALL_BUFFERS(buf)
        if (n < buf->b_fnum)
            n = buf->b_fnum;
 
@@ -12373,7 +12373,7 @@ f_winrestcmd(typval_T *argvars UNUSED, typval_T *rettv)
     char_u     buf[50];
 
     ga_init2(&ga, (int)sizeof(char), 70);
-    for (wp = firstwin; wp != NULL; wp = wp->w_next)
+    FOR_ALL_WINDOWS(wp)
     {
        sprintf((char *)buf, "%dresize %d|", winnr, wp->w_height);
        ga_concat(&ga, buf);
index 7ec17b132c2551e52aa871b437c72176d0364aed..7d8196cdc005998e4b83540cdfd4161356d07baa 100644 (file)
@@ -1497,7 +1497,7 @@ do_shell(
                && !autocmd_busy
 #endif
                && msg_silent == 0)
-       for (buf = firstbuf; buf; buf = buf->b_next)
+       FOR_ALL_BUFFERS(buf)
            if (bufIsChanged(buf))
            {
 #ifdef FEAT_GUI_MSWIN
@@ -2345,7 +2345,7 @@ read_viminfo_up_to_marks(
 #endif
 
     /* Change file names to buffer numbers for fmarks. */
-    for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+    FOR_ALL_BUFFERS(buf)
        fmarks_check_names(buf);
 
     return eof;
@@ -3413,7 +3413,7 @@ do_wqall(exarg_T *eap)
     if (eap->cmdidx == CMD_xall || eap->cmdidx == CMD_wqall)
        exiting = TRUE;
 
-    for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+    FOR_ALL_BUFFERS(buf)
     {
        if (bufIsChanged(buf))
        {
@@ -6115,7 +6115,7 @@ prepare_tagpreview(
      */
     if (!curwin->w_p_pvw)
     {
-       for (wp = firstwin; wp != NULL; wp = wp->w_next)
+       FOR_ALL_WINDOWS(wp)
            if (wp->w_p_pvw)
                break;
        if (wp != NULL)
@@ -6272,7 +6272,7 @@ ex_help(exarg_T *eap)
        if (cmdmod.tab != 0)
            wp = NULL;
        else
-           for (wp = firstwin; wp != NULL; wp = wp->w_next)
+           FOR_ALL_WINDOWS(wp)
                if (wp->w_buffer != NULL && wp->w_buffer->b_help)
                    break;
        if (wp != NULL && wp->w_buffer->b_nwindows > 0)
@@ -7745,7 +7745,7 @@ ex_sign(exarg_T *eap)
                if (idx == SIGNCMD_UNPLACE && *arg == NUL)
                {
                    /* ":sign unplace {id}": remove placed sign by number */
-                   for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+                   FOR_ALL_BUFFERS(buf)
                        if ((lnum = buf_delsign(buf, id)) != 0)
                            update_debug_sign(buf, lnum);
                    return;
index adc53529b4471d2e56d69ac629cc2b3aa9e02392..83305b240743bd54aa55637af3576c4d1eb9dbc7 100644 (file)
@@ -1721,7 +1721,7 @@ autowrite_all(void)
 
     if (!(p_aw || p_awa) || !p_write)
        return;
-    for (buf = firstbuf; buf; buf = buf->b_next)
+    FOR_ALL_BUFFERS(buf)
        if (bufIsChanged(buf) && !buf->b_p_ro)
        {
 #ifdef FEAT_AUTOCMD
@@ -1764,7 +1764,7 @@ check_changed(buf_T *buf, int flags)
            int         count = 0;
 
            if (flags & CCGD_ALLBUF)
-               for (buf2 = firstbuf; buf2 != NULL; buf2 = buf2->b_next)
+               FOR_ALL_BUFFERS(buf2)
                    if (bufIsChanged(buf2)
                                     && (buf2->b_ffname != NULL
 # ifdef FEAT_BROWSE
@@ -1868,7 +1868,7 @@ dialog_changed(
         * Skip readonly buffers, these need to be confirmed
         * individually.
         */
-       for (buf2 = firstbuf; buf2 != NULL; buf2 = buf2->b_next)
+       FOR_ALL_BUFFERS(buf2)
        {
            if (bufIsChanged(buf2)
                    && (buf2->b_ffname != NULL
@@ -1904,7 +1904,7 @@ dialog_changed(
        /*
         * mark all buffers as unchanged
         */
-       for (buf2 = firstbuf; buf2 != NULL; buf2 = buf2->b_next)
+       FOR_ALL_BUFFERS(buf2)
            unchanged(buf2, TRUE);
     }
 }
@@ -1964,7 +1964,7 @@ check_changed_any(
     win_T      *wp;
 #endif
 
-    for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+    FOR_ALL_BUFFERS(buf)
        ++bufcount;
 
     if (bufcount == 0)
@@ -1983,13 +1983,13 @@ check_changed_any(
            add_bufnum(bufnrs, &bufnum, wp->w_buffer->b_fnum);
 
     /* buf in other tab */
-    for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+    FOR_ALL_TABPAGES(tp)
        if (tp != curtab)
            for (wp = tp->tp_firstwin; wp != NULL; wp = wp->w_next)
                add_bufnum(bufnrs, &bufnum, wp->w_buffer->b_fnum);
 #endif
     /* any other buf */
-    for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+    FOR_ALL_BUFFERS(buf)
        add_bufnum(bufnrs, &bufnum, buf->b_fnum);
 
     for (i = 0; i < bufnum; ++i)
@@ -2924,7 +2924,7 @@ ex_listdo(exarg_T *eap)
                if (next_fnum < 0 || next_fnum > eap->line2)
                    break;
                /* Check if the buffer still exists. */
-               for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+               FOR_ALL_BUFFERS(buf)
                    if (buf->b_fnum == next_fnum)
                        break;
                if (buf == NULL)
index 41a228d22906584e80443bd0cb8ec9313e95a7ad..28de56ab056551220b95830720d189cec26cbdd4 100644 (file)
@@ -1708,7 +1708,7 @@ current_win_nr(win_T *win)
     win_T      *wp;
     int                nr = 0;
 
-    for (wp = firstwin; wp != NULL; wp = wp->w_next)
+    FOR_ALL_WINDOWS(wp)
     {
        ++nr;
        if (wp == win)
@@ -1723,7 +1723,7 @@ current_tab_nr(tabpage_T *tab)
     tabpage_T  *tp;
     int                nr = 0;
 
-    for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+    FOR_ALL_TABPAGES(tp)
     {
        ++nr;
        if (tp == tab)
@@ -7273,7 +7273,7 @@ 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(win)
                {
                    winnr++;
                    if (winnr == eap->line2)
@@ -7295,7 +7295,7 @@ ex_pclose(exarg_T *eap)
 {
     win_T      *win;
 
-    for (win = firstwin; win != NULL; win = win->w_next)
+    FOR_ALL_WINDOWS(win)
        if (win->w_p_pvw)
        {
            ex_win_close(eap->forceit, win, NULL);
@@ -7415,7 +7415,7 @@ ex_tabonly(exarg_T *eap)
             * up the lists. */
            for (done = 0; done < 1000; ++done)
            {
-               for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+               FOR_ALL_TABPAGES(tp)
                    if (tp->tp_topframe != topframe)
                    {
                        tabpage_close_other(tp, eap->forceit);
@@ -7474,6 +7474,10 @@ tabpage_close_other(tabpage_T *tp, int forceit)
            break;
     }
 
+#ifdef FEAT_AUTOCMD
+    apply_autocmds(EVENT_TABCLOSED, NULL, NULL, FALSE, curbuf);
+#endif
+
     redraw_tabline = TRUE;
     if (h != tabline_height())
        shell_new_rows();
@@ -7540,7 +7544,7 @@ ex_hide(exarg_T *eap)
                int     winnr = 0;
                win_T   *win;
 
-               for (win = firstwin; win != NULL; win = win->w_next)
+               FOR_ALL_WINDOWS(win)
                {
                    winnr++;
                    if (winnr == eap->line2)
@@ -8686,7 +8690,7 @@ ex_syncbind(exarg_T *eap UNUSED)
     if (curwin->w_p_scb)
     {
        topline = curwin->w_topline;
-       for (wp = firstwin; wp; wp = wp->w_next)
+       FOR_ALL_WINDOWS(wp)
        {
            if (wp->w_p_scb && wp->w_buffer)
            {
@@ -8707,7 +8711,7 @@ ex_syncbind(exarg_T *eap UNUSED)
     /*
      * Set all scrollbind windows to the same topline.
      */
-    for (curwin = firstwin; curwin; curwin = curwin->w_next)
+    FOR_ALL_WINDOWS(curwin)
     {
        if (curwin->w_p_scb)
        {
@@ -10957,7 +10961,7 @@ makeopens(
        return FAIL;
 
     /* Now put the other buffers into the buffer list */
-    for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+    FOR_ALL_BUFFERS(buf)
     {
        if (!(only_save_windows && buf->b_nwindows == 0)
                && !(buf->b_help && !(ssop_flags & SSOP_HELP))
index ea01b763f0cdb268ab432fbb9b84692bbd0f7a15..c4066173d270e1e8347569bb633b8031d77269a1 100644 (file)
@@ -6088,7 +6088,7 @@ shorten_fnames(int force)
     char_u     *p;
 
     mch_dirname(dirname, MAXPATHL);
-    for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+    FOR_ALL_BUFFERS(buf)
     {
        if (buf->b_fname != NULL
 #ifdef FEAT_QUICKFIX
@@ -6680,7 +6680,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)
@@ -6699,7 +6699,6 @@ check_timestamps(
                    continue;
                }
            }
-           buf = buf->b_next;
        }
        --no_wait_return;
        need_check_timestamps = FALSE;
@@ -8759,7 +8758,7 @@ ex_doautoall(exarg_T *eap)
      * gives problems when the autocommands make changes to the list of
      * buffers or windows...
      */
-    for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+    FOR_ALL_BUFFERS(buf)
     {
        if (buf->b_ml.ml_mfp != NULL)
        {
@@ -8831,7 +8830,7 @@ aucmd_prepbuf(
        win = curwin;
     else
 #ifdef FEAT_WINDOWS
-       for (win = firstwin; win != NULL; win = win->w_next)
+       FOR_ALL_WINDOWS(win)
            if (win->w_buffer == buf)
                break;
 #else
index b569680a412a5586522f5431d5876b0b6a2d7c6e..a3d6b4ee24e555253a0af8e03703bdcf7c484d93 100644 (file)
@@ -548,6 +548,10 @@ EXTERN win_T       *lastwin;               /* last window */
 EXTERN win_T   *prevwin INIT(= NULL);  /* previous window */
 # define W_NEXT(wp) ((wp)->w_next)
 # define FOR_ALL_WINDOWS(wp) for (wp = firstwin; wp != NULL; wp = wp->w_next)
+# define FOR_ALL_TABPAGES(tp) for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+# define FOR_ALL_WINDOWS_IN_TAB(tp, wp) \
+    for ((wp) = ((tp) == NULL || (tp) == curtab) \
+           ? firstwin : (tp)->tp_firstwin; (wp); (wp) = (wp)->w_next)
 /*
  * When using this macro "break" only breaks out of the inner loop. Use "goto"
  * to break out of the tabpage loop.
@@ -561,6 +565,8 @@ EXTERN win_T        *prevwin INIT(= NULL);  /* previous window */
 # define lastwin curwin
 # define W_NEXT(wp) NULL
 # define FOR_ALL_WINDOWS(wp) wp = curwin;
+# define FOR_ALL_TABPAGES(tp) for (;FALSE;)
+# define FOR_ALL_WINDOWS_IN_TAB(tp, wp) wp = curwin;
 # define FOR_ALL_TAB_WINDOWS(tp, wp) wp = curwin;
 #endif
 
@@ -595,6 +601,8 @@ EXTERN buf_T        *firstbuf INIT(= NULL); /* first buffer */
 EXTERN buf_T   *lastbuf INIT(= NULL);  /* last buffer */
 EXTERN buf_T   *curbuf INIT(= NULL);   /* currently active buffer */
 
+#define FOR_ALL_BUFFERS(buf) for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+
 /* Flag that is set when switching off 'swapfile'.  It means that all blocks
  * are to be loaded into memory.  Shouldn't be global... */
 EXTERN int     mf_dont_release INIT(= FALSE);  /* don't release blocks */
index d4fd68aaeb62567c8854483ffce5d32bda2fe44a..ea049c39d5b68bf027df7fb818fad2d32ea3f32d 100644 (file)
--- a/src/gui.c
+++ b/src/gui.c
@@ -4082,7 +4082,7 @@ gui_drag_scrollbar(scrollbar_T *sb, long value, int still_dragging)
     {
        do_check_scrollbind(TRUE);
        /* need to update the window right here */
-       for (wp = firstwin; wp != NULL; wp = wp->w_next)
+       FOR_ALL_WINDOWS(wp)
            if (wp->w_redr_type > 0)
                updateWindow(wp);
        setcursor();
@@ -4166,7 +4166,7 @@ gui_update_scrollbars(
     /* avoid that moving components around generates events */
     ++hold_gui_events;
 
-    for (wp = firstwin; wp != NULL; wp = W_NEXT(wp))
+    FOR_ALL_WINDOWS(wp)
     {
        if (wp->w_buffer == NULL)       /* just in case */
            continue;
index b2e4d4b3f7d415034529dd44f8fd24d3d36997e4..b78c903bea1e498515e0a409a36e3a969d10817a 100644 (file)
@@ -633,7 +633,7 @@ Handle_KAHL_SRCH_AE(
     if (error)
        return error;
 
-    for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+    FOR_ALL_BUFFERS(buf)
        if (buf->b_ml.ml_mfp != NULL
                && SearchData.theFile.parID == buf->b_FSSpec.parID
                && SearchData.theFile.name[0] == buf->b_FSSpec.name[0]
@@ -725,7 +725,7 @@ Handle_KAHL_MOD_AE(
 #endif
 
     numFiles = 0;
-    for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+    FOR_ALL_BUFFERS(buf)
        if (buf->b_ml.ml_mfp != NULL)
        {
            /* Add this file to the list */
@@ -807,7 +807,7 @@ Handle_KAHL_GTTX_AE(
     if (error)
        return error;
 
-    for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+    FOR_ALL_BUFFERS(buf)
        if (buf->b_ml.ml_mfp != NULL)
            if (GetTextData.theFile.parID == buf->b_FSSpec.parID)
            {
@@ -6422,7 +6422,7 @@ getTabCount(void)
     tabpage_T  *tp;
     int                numTabs = 0;
 
-    for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+    FOR_ALL_TABPAGES(tp)
        ++numTabs;
     return numTabs;
 }
index 8d761004d3213dc150bfd50a2d2cb8c6d2f02d64..5803d07912b9f7b6e2eb2a24a5ae90193f04521f 100644 (file)
@@ -1402,13 +1402,13 @@ luaV_buffer(lua_State *L)
        if (lua_isnumber(L, 1)) /* by number? */
        {
            int n = lua_tointeger(L, 1);
-           for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+           FOR_ALL_BUFFERS(buf)
                if (buf->b_fnum == n) break;
        }
        else { /* by name */
            size_t l;
            const char *s = lua_tolstring(L, 1, &l);
-           for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+           FOR_ALL_BUFFERS(buf)
            {
                if (buf->b_ffname == NULL || buf->b_sfname == NULL)
                {
index 645548f8021d0ab85fa894782883c45f7a3f10fd..daec6b0a82e6bf6fececd1e9e5a516a300ab4d2d 100644 (file)
@@ -1916,7 +1916,7 @@ get_window_count(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED
 #ifdef FEAT_WINDOWS
     win_T   *w;
 
-    for (w = firstwin; w != NULL; w = w->w_next)
+    FOR_ALL_WINDOWS(w)
 #endif
        ++n;
     return scheme_make_integer(n);
@@ -2197,7 +2197,7 @@ get_buffer_by_num(void *data, int argc, Scheme_Object **argv)
 
     fnum = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0));
 
-    for (buf = firstbuf; buf; buf = buf->b_next)
+    FOR_ALL_BUFFERS(buf)
        if (buf->b_fnum == fnum)
            return buffer_new(buf);
 
@@ -2220,7 +2220,7 @@ get_buffer_by_name(void *data, int argc, Scheme_Object **argv)
     fname = GUARANTEED_STRING_ARG(prim->name, 0);
     buffer = scheme_false;
 
-    for (buf = firstbuf; buf; buf = buf->b_next)
+    FOR_ALL_BUFFERS(buf)
     {
        if (buf->b_ffname == NULL || buf->b_sfname == NULL)
            /* empty string */
@@ -2283,7 +2283,7 @@ get_buffer_count(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED
     buf_T   *b;
     int            n = 0;
 
-    for (b = firstbuf; b; b = b->b_next) ++n;
+    FOR_ALL_BUFFERS(b) ++n;
     return scheme_make_integer(n);
 }
 
index a2ff45208a4c111f9cbcfddb03958879511e7466..5b5023c07ee215afba47ce4fcf7a274628b00767 100644 (file)
@@ -1534,14 +1534,14 @@ Buffers(...)
        if (GIMME == G_SCALAR)
        {
            i = 0;
-           for (vimbuf = firstbuf; vimbuf; vimbuf = vimbuf->b_next)
+           FOR_ALL_BUFFERS(vimbuf)
                ++i;
 
            XPUSHs(sv_2mortal(newSViv(i)));
        }
        else
        {
-           for (vimbuf = firstbuf; vimbuf; vimbuf = vimbuf->b_next)
+           FOR_ALL_BUFFERS(vimbuf)
                XPUSHs(newBUFrv(newSV(0), vimbuf));
        }
     }
@@ -1586,7 +1586,7 @@ Windows(...)
            XPUSHs(sv_2mortal(newSViv(win_count())));
        else
        {
-           for (vimwin = firstwin; vimwin != NULL; vimwin = W_NEXT(vimwin))
+           FOR_ALL_WINDOWS(vimwin)
                XPUSHs(newWINrv(newSV(0), vimwin));
        }
     }
index f0c441ada5c4f130c56f0d90c4aa39049612d2f8..7111b993e517a55333ed16695f95c51623fde849 100644 (file)
@@ -1151,7 +1151,7 @@ static VALUE buffer_s_count(void)
     buf_T *b;
     int n = 0;
 
-    for (b = firstbuf; b != NULL; b = b->b_next)
+    FOR_ALL_BUFFERS(b)
     {
        /*  Deleted buffers should not be counted
         *    SegPhault - 01/07/05 */
@@ -1167,7 +1167,7 @@ static VALUE buffer_s_aref(VALUE self UNUSED, VALUE num)
     buf_T *b;
     int n = NUM2INT(num);
 
-    for (b = firstbuf; b != NULL; b = b->b_next)
+    FOR_ALL_BUFFERS(b)
     {
        /*  Deleted buffers should not be counted
         *    SegPhault - 01/07/05 */
@@ -1418,7 +1418,7 @@ static VALUE window_s_count(void)
     win_T      *w;
     int n = 0;
 
-    for (w = firstwin; w != NULL; w = w->w_next)
+    FOR_ALL_WINDOWS(w)
        n++;
     return INT2NUM(n);
 #else
index 3ef154458717361de267877c01d67a49fe603e79..a1d8d1a38cee90b3e7444606605ea76b90f6b1d5 100644 (file)
@@ -388,7 +388,7 @@ buffercmd(
            Tcl_WrongNumArgs(interp, 1, objv, "bufNumber");
            return TCL_ERROR;
        }
-       for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+       FOR_ALL_BUFFERS(buf)
        {
            if (buf->b_fnum == n)
            {
@@ -416,7 +416,7 @@ buffercmd(
                err = TCL_ERROR;
                break;
            }
-           for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+           FOR_ALL_BUFFERS(buf)
            {
                name = tclgetbuffer(interp, buf);
                if (name == NULL)
index ff82a9f16044ef959f2fde27104977571e0a743e..926b8ab909030edaf0401a7e6ce709ee373ef555 100644 (file)
@@ -742,7 +742,7 @@ vim_main2(int argc UNUSED, char **argv UNUSED)
        win_T   *wp;
 
        /* set options in each window for "vimdiff". */
-       for (wp = firstwin; wp != NULL; wp = wp->w_next)
+       FOR_ALL_WINDOWS(wp)
            diff_win_options(wp, TRUE);
     }
 #endif
@@ -1375,8 +1375,7 @@ getout(int exitval)
        for (tp = first_tabpage; tp != NULL; tp = next_tp)
        {
            next_tp = tp->tp_next;
-           for (wp = (tp == curtab)
-                   ? firstwin : tp->tp_firstwin; wp != NULL; wp = wp->w_next)
+           FOR_ALL_WINDOWS_IN_TAB(tp, wp)
            {
                if (wp->w_buffer == NULL)
                    /* Autocmd must have close the buffer already, skip. */
@@ -1399,7 +1398,7 @@ getout(int exitval)
 # endif
 
        /* Trigger BufUnload for buffers that are loaded */
-       for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+       FOR_ALL_BUFFERS(buf)
            if (buf->b_ml.ml_mfp != NULL)
            {
                bufref_T bufref;
index 1e6b26a7ac76e2b8187068ee191a567159febeb7..9f0faf93b1240b3756edaa13e083d7ea5aae66a2 100644 (file)
@@ -1864,7 +1864,7 @@ write_viminfo_marks(FILE *fp_out, garray_T *buflist)
 #endif
 
     fputs(_("\n# History of marks within files (newest to oldest):\n"), fp_out);
-    for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+    FOR_ALL_BUFFERS(buf)
     {
        /*
         * Only write something if buffer has been loaded and at least one
@@ -2018,7 +2018,7 @@ copy_viminfo_marks(
        else /* fp_out != NULL */
        {
            /* This is slow if there are many buffers!! */
-           for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+           FOR_ALL_BUFFERS(buf)
                if (buf->b_ffname != NULL)
                {
                    home_replace(NULL, buf->b_ffname, name_buf, LSIZE, TRUE);
index e2fadc2e53e580ca14e5ed0b941576a85b3c3000..4a4843000660a1f2f821888ca98ea4dfb2998e16 100644 (file)
@@ -796,7 +796,7 @@ mf_release(memfile_T *mfp, int page_count)
     if (mfp->mf_fd < 0 && need_release && p_uc)
     {
        /* find for which buffer this memfile is */
-       for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+       FOR_ALL_BUFFERS(buf)
            if (buf->b_ml.ml_mfp == mfp)
                break;
        if (buf != NULL && buf->b_may_swap)
@@ -861,7 +861,7 @@ mf_release_all(void)
     bhdr_T     *hp;
     int                retval = FALSE;
 
-    for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+    FOR_ALL_BUFFERS(buf)
     {
        mfp = buf->b_ml.ml_mfp;
        if (mfp != NULL)
index f7c68b2da817780350d40fa88bfa5ed1ae01ef93..8f5cf5d0e5ce4193b9649ae4cfd6d85319e013b5 100644 (file)
@@ -739,7 +739,7 @@ ml_open_files(void)
 {
     buf_T      *buf;
 
-    for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+    FOR_ALL_BUFFERS(buf)
        if (!buf->b_p_ro || buf->b_changed)
            ml_open_file(buf);
 }
@@ -873,7 +873,7 @@ ml_close_all(int del_file)
 {
     buf_T      *buf;
 
-    for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+    FOR_ALL_BUFFERS(buf)
        ml_close(buf, del_file && ((buf->b_flags & BF_PRESERVED) == 0
                                 || vim_strchr(p_cpo, CPO_PRESERVE) == NULL));
 #ifdef FEAT_SPELL
@@ -893,7 +893,7 @@ ml_close_notmod(void)
 {
     buf_T      *buf;
 
-    for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+    FOR_ALL_BUFFERS(buf)
        if (!bufIsChanged(buf))
            ml_close(buf, TRUE);    /* close all not-modified buffers */
 }
@@ -2264,7 +2264,7 @@ ml_sync_all(int check_file, int check_char)
     buf_T              *buf;
     stat_T             st;
 
-    for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+    FOR_ALL_BUFFERS(buf)
     {
        if (buf->b_ml.ml_mfp == NULL || buf->b_ml.ml_mfp->mf_fname == NULL)
            continue;                       /* no file */
index 293ac9e9357bd2a2e15a3e8c072141f7ed00b023..2ee87b1f2053843b017a3d9b09ce0ffc96651a90 100644 (file)
@@ -2814,7 +2814,7 @@ changed_bytes(linenr_T lnum, colnr_T col)
        win_T       *wp;
        linenr_T    wlnum;
 
-       for (wp = firstwin; wp != NULL; wp = wp->w_next)
+       FOR_ALL_WINDOWS(wp)
            if (wp->w_p_diff && wp != curwin)
            {
                redraw_win_later(wp, VALID);
@@ -2924,7 +2924,7 @@ changed_lines(
        win_T       *wp;
        linenr_T    wlnum;
 
-       for (wp = firstwin; wp != NULL; wp = wp->w_next)
+       FOR_ALL_WINDOWS(wp)
            if (wp->w_p_diff && wp != curwin)
            {
                redraw_win_later(wp, VALID);
@@ -3213,7 +3213,7 @@ check_status(buf_T *buf)
 {
     win_T      *wp;
 
-    for (wp = firstwin; wp != NULL; wp = wp->w_next)
+    FOR_ALL_WINDOWS(wp)
        if (wp->w_buffer == buf && wp->w_status_height)
        {
            wp->w_redr_status = TRUE;
@@ -9475,7 +9475,7 @@ preserve_exit(void)
 
     ml_close_notmod();             /* close all not-modified buffers */
 
-    for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+    FOR_ALL_BUFFERS(buf)
     {
        if (buf->b_ml.ml_mfp != NULL && buf->b_ml.ml_mfp->mf_fname != NULL)
        {
index 1a00a4d16eb90c769cc02753cf81e26f81ec72d3..136263f22aeab58d75b1b4b932d4eb87c0c70fa3 100644 (file)
@@ -2820,7 +2820,7 @@ 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(curwin)
     {
        curbuf = curwin->w_buffer;
        /* skip original window  and windows with 'noscrollbind' */
index 7d6ec43444dc536275e8d468b1fc55147295bcf0..f1e76664005468d7f948183fd79ee09859ac7728 100644 (file)
@@ -473,7 +473,7 @@ nb_parse_cmd(char_u *cmd)
     {
        buf_T   *buf;
 
-       for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+       FOR_ALL_BUFFERS(buf)
            buf->b_has_sign_column = FALSE;
 
        /* The IDE is breaking the connection. */
@@ -721,7 +721,7 @@ count_changed_buffers(void)
     int                n;
 
     n = 0;
-    for (bufp = firstbuf; bufp != NULL; bufp = bufp->b_next)
+    FOR_ALL_BUFFERS(bufp)
        if (bufp->b_changed)
            ++n;
     return n;
index bc72c811bc8ebca142d357c466a944f38e345df9..bbcd6180bbb6425e9033733470e314fe6f75e2d1 100644 (file)
@@ -4073,7 +4073,7 @@ 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(curwin)
     {
        curbuf = curwin->w_buffer;
        /* skip original window  and windows with 'noscrollbind' */
index 288c01bbaaf258a55543391c13756fcb6f404aa3..b9b59eefd014b78e829727ac1a466dc7d4a30296 100644 (file)
@@ -6342,7 +6342,7 @@ did_set_string_option(
            {
                buf_T   *buf;
 
-               for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+               FOR_ALL_BUFFERS(buf)
                    if (buf != curbuf && *buf->b_p_cm == NUL)
                        ml_set_crypt_key(buf, buf->b_p_key, oldval);
            }
@@ -7864,7 +7864,7 @@ 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(curbuf)
            {
                /* When 'undofile' is set globally: for every buffer, otherwise
                 * only for the current buffer: Try to read in the undofile,
@@ -8040,7 +8040,7 @@ set_bool_option(
        {
            win_T       *win;
 
-           for (win = firstwin; win != NULL; win = win->w_next)
+           FOR_ALL_WINDOWS(win)
                if (win->w_p_pvw && win != curwin)
                {
                    curwin->w_p_pvw = FALSE;
@@ -11651,7 +11651,7 @@ paste_option_changed(void)
        if (!old_p_paste)
        {
            /* save options for each buffer */
-           for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+           FOR_ALL_BUFFERS(buf)
            {
                buf->b_p_tw_nopaste = buf->b_p_tw;
                buf->b_p_wm_nopaste = buf->b_p_wm;
@@ -11683,7 +11683,7 @@ paste_option_changed(void)
         * already on.
         */
        /* set options for each buffer */
-       for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+       FOR_ALL_BUFFERS(buf)
        {
            buf->b_p_tw = 0;        /* textwidth is 0 */
            buf->b_p_wm = 0;        /* wrapmargin is 0 */
@@ -11719,7 +11719,7 @@ paste_option_changed(void)
     else if (old_p_paste)
     {
        /* restore options for each buffer */
-       for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+       FOR_ALL_BUFFERS(buf)
        {
            buf->b_p_tw = buf->b_p_tw_nopaste;
            buf->b_p_wm = buf->b_p_wm_nopaste;
index 51f96dcaa443bc4814e52be310bb2c5cbc02574c..b6071709df80463b35d17b96426b04d593877952 100644 (file)
@@ -2040,7 +2040,7 @@ qf_jump(
        if (cmdmod.tab != 0)
            wp = NULL;
        else
-           for (wp = firstwin; wp != NULL; wp = wp->w_next)
+           FOR_ALL_WINDOWS(wp)
                if (wp->w_buffer != NULL && wp->w_buffer->b_help)
                    break;
        if (wp != NULL && wp->w_buffer->b_nwindows > 0)
index ccdf98c583c796e4d915d49d826e5ffd8e92113b..1b364a4a2c5c9088ff227c88fe0e72a3b7606cab 100644 (file)
@@ -730,7 +730,7 @@ update_screen(int type)
 #ifdef FEAT_WINDOWS
     /* Reset b_mod_set flags.  Going through all windows is probably faster
      * than going through all buffers (there could be many buffers). */
-    for (wp = firstwin; wp != NULL; wp = wp->w_next)
+    FOR_ALL_WINDOWS(wp)
        wp->w_buffer->b_mod_set = FALSE;
 #else
        curbuf->b_mod_set = FALSE;
@@ -962,7 +962,7 @@ update_debug_sign(buf_T *buf, linenr_T lnum)
     update_prepare();
 
 # ifdef FEAT_WINDOWS
-    for (wp = firstwin; wp; wp = wp->w_next)
+    FOR_ALL_WINDOWS(wp)
     {
        if (wp->w_redr_type != 0)
            win_update(wp);
@@ -6271,7 +6271,7 @@ status_redraw_all(void)
 {
     win_T      *wp;
 
-    for (wp = firstwin; wp; wp = wp->w_next)
+    FOR_ALL_WINDOWS(wp)
        if (wp->w_status_height)
        {
            wp->w_redr_status = TRUE;
@@ -6287,7 +6287,7 @@ status_redraw_curbuf(void)
 {
     win_T      *wp;
 
-    for (wp = firstwin; wp; wp = wp->w_next)
+    FOR_ALL_WINDOWS(wp)
        if (wp->w_status_height != 0 && wp->w_buffer == curbuf)
        {
            wp->w_redr_status = TRUE;
@@ -6303,7 +6303,7 @@ redraw_statuslines(void)
 {
     win_T      *wp;
 
-    for (wp = firstwin; wp; wp = wp->w_next)
+    FOR_ALL_WINDOWS(wp)
        if (wp->w_redr_status)
            win_redr_status(wp);
     if (redraw_tabline)
@@ -10360,7 +10360,7 @@ draw_tabline(void)
     else
 #endif
     {
-       for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+       FOR_ALL_TABPAGES(tp)
            ++tabcount;
 
        tabwidth = (Columns - 1 + tabcount / 2) / tabcount;
index 0f09c122d90a742715f42d21c1a70d34529908f6..35235e04be39aa34aee59cbb09f9835ac7eaff2f 100644 (file)
@@ -2875,7 +2875,7 @@ spell_free_all(void)
     buf_T      *buf;
 
     /* Go through all buffers and handle 'spelllang'. <VN> */
-    for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+    FOR_ALL_BUFFERS(buf)
        ga_clear(&buf->b_s.b_langp);
 
     while (first_lang != NULL)
@@ -2911,7 +2911,7 @@ spell_reload(void)
     spell_free_all();
 
     /* Go through all buffers and handle 'spelllang'. */
-    for (wp = firstwin; wp != NULL; wp = wp->w_next)
+    FOR_ALL_WINDOWS(wp)
     {
        /* Only load the wordlists when 'spelllang' is set and there is a
         * window for this buffer in which 'spell' is set. */
index 506cf3c086a6eaf52ad39ddef4f88d12cd8c92d8..6af82db0c563249fdd590ace9623031103a7bad6 100644 (file)
@@ -1907,7 +1907,7 @@ set_termname(char_u *term)
             * loaded.
             */
            set_bufref(&old_curbuf, curbuf);
-           for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
+           FOR_ALL_BUFFERS(curbuf)
            {
                if (curbuf->b_ml.ml_mfp != NULL)
                    apply_autocmds(EVENT_TERMCHANGED, NULL, NULL, FALSE,
index 233b6b54bad103e9325c034a47440f1b166a88d2..0b63a299d1d27526d9df027b0c10cd15c7a2b163 100644 (file)
@@ -758,6 +758,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2101,
 /**/
     2100,
 /**/
index 4fbe6ca58524cd36f9e72861806aea62f3ee9dc1..925a1471302f588d6b12a3c2ba9682c7e88acc15 100644 (file)
@@ -209,7 +209,7 @@ newwindow:
 
 /* cursor to preview window */
     case 'P':
-               for (wp = firstwin; wp != NULL; wp = wp->w_next)
+               FOR_ALL_WINDOWS(wp)
                    if (wp->w_p_pvw)
                        break;
                if (wp == NULL)
@@ -1367,7 +1367,7 @@ win_valid(win_T *win)
 
     if (win == NULL)
        return FALSE;
-    for (wp = firstwin; wp != NULL; wp = wp->w_next)
+    FOR_ALL_WINDOWS(wp)
        if (wp == win)
            return TRUE;
     return FALSE;
@@ -1382,7 +1382,7 @@ win_count(void)
     win_T      *wp;
     int                count = 0;
 
-    for (wp = firstwin; wp != NULL; wp = wp->w_next)
+    FOR_ALL_WINDOWS(wp)
        ++count;
     return count;
 }
@@ -3712,7 +3712,7 @@ valid_tabpage(tabpage_T *tpc)
 {
     tabpage_T  *tp;
 
-    for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+    FOR_ALL_TABPAGES(tp)
        if (tp == tpc)
            return TRUE;
     return FALSE;
@@ -4012,7 +4012,7 @@ tabpage_move(int nr)
        first_tabpage = curtab->tp_next;
     else
     {
-       for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+       FOR_ALL_TABPAGES(tp)
            if (tp->tp_next == curtab)
                break;
        if (tp == NULL) /* "cannot happen" */
@@ -4091,7 +4091,7 @@ win_find_nr(int winnr)
     win_T      *wp;
 
 # ifdef FEAT_WINDOWS
-    for (wp = firstwin; wp != NULL; wp = wp->w_next)
+    FOR_ALL_WINDOWS(wp)
        if (--winnr == 0)
            break;
     return wp;
@@ -4112,9 +4112,7 @@ 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)
+    FOR_ALL_TAB_WINDOWS(tp, wp)
            if (wp == win)
                return tp;
     return NULL;
@@ -4404,7 +4402,7 @@ buf_jump_open_win(buf_T *buf)
        wp = curwin;
 # ifdef FEAT_WINDOWS
     else
-       for (wp = firstwin; wp != NULL; wp = wp->w_next)
+       FOR_ALL_WINDOWS(wp)
            if (wp->w_buffer == buf)
                break;
     if (wp != NULL)
@@ -4428,7 +4426,7 @@ buf_jump_open_tab(buf_T *buf)
     if (wp != NULL)
        return wp;
 
-    for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+    FOR_ALL_TABPAGES(tp)
        if (tp != curtab)
        {
            for (wp = tp->tp_firstwin; wp != NULL; wp = wp->w_next)
@@ -4607,7 +4605,7 @@ win_free(
 
        if (prevwin == wp)
            prevwin = NULL;
-       for (ttp = first_tabpage; ttp != NULL; ttp = ttp->tp_next)
+       FOR_ALL_TABPAGES(ttp)
            if (ttp->tp_prevwin == wp)
                ttp->tp_prevwin = NULL;
     }
@@ -4620,7 +4618,7 @@ win_free(
 
     /* Remove the window from the b_wininfo lists, it may happen that the
      * freed memory is re-used for another window. */
-    for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+    FOR_ALL_BUFFERS(buf)
        for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next)
            if (wip->wi_win == wp)
                wip->wi_win = NULL;
@@ -4863,7 +4861,7 @@ win_size_save(garray_T *gap)
 
     ga_init2(gap, (int)sizeof(int), 1);
     if (ga_grow(gap, win_count() * 2) == OK)
-       for (wp = firstwin; wp != NULL; wp = wp->w_next)
+       FOR_ALL_WINDOWS(wp)
        {
            ((int *)gap->ga_data)[gap->ga_len++] =
                                               wp->w_width + wp->w_vsep_width;
@@ -4888,7 +4886,7 @@ win_size_restore(garray_T *gap)
        for (j = 0; j < 2; ++j)
        {
            i = 0;
-           for (wp = firstwin; wp != NULL; wp = wp->w_next)
+           FOR_ALL_WINDOWS(wp)
            {
                frame_setwidth(wp->w_frame, ((int *)gap->ga_data)[i++]);
                win_setheight_win(((int *)gap->ga_data)[i++], wp);
@@ -5384,7 +5382,7 @@ win_setminheight(void)
     {
        /* TODO: handle vertical splits */
        room = -p_wh;
-       for (wp = firstwin; wp != NULL; wp = wp->w_next)
+       FOR_ALL_WINDOWS(wp)
            room += wp->w_height - p_wmh;
        if (room >= 0)
            break;
@@ -6344,7 +6342,7 @@ min_rows(void)
 
 #ifdef FEAT_WINDOWS
     total = 0;
-    for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+    FOR_ALL_TABPAGES(tp)
     {
        n = frame_minheight(tp->tp_topframe, NULL);
        if (total < n)
@@ -6374,7 +6372,7 @@ only_one_window(void)
     if (first_tabpage->tp_next != NULL)
        return FALSE;
 
-    for (wp = firstwin; wp != NULL; wp = wp->w_next)
+    FOR_ALL_WINDOWS(wp)
        if (wp->w_buffer != NULL
                && (!((wp->w_buffer->b_help && !curbuf->b_help)
 # ifdef FEAT_QUICKFIX
@@ -7091,7 +7089,7 @@ win_getid(typval_T *argvars)
            tabpage_T   *tp;
            int         tabnr = get_tv_number(&argvars[1]);
 
-           for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+           FOR_ALL_TABPAGES(tp)
                if (--tabnr == 0)
                    break;
            if (tp == NULL)
@@ -7112,9 +7110,7 @@ win_gotoid(typval_T *argvars)
     tabpage_T   *tp;
     int                id = get_tv_number(&argvars[0]);
 
-    for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
-       for (wp = tp == curtab ? firstwin : tp->tp_firstwin;
-                                                 wp != NULL; wp = wp->w_next)
+    FOR_ALL_TAB_WINDOWS(tp, wp)
            if (wp->w_id == id)
            {
                goto_tabpage_win(tp, wp);
@@ -7132,10 +7128,9 @@ win_id2tabwin(typval_T *argvars, list_T *list)
     int                tabnr = 1;
     int                id = get_tv_number(&argvars[0]);
 
-    for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+    FOR_ALL_TABPAGES(tp)
     {
-       for (wp = tp == curtab ? firstwin : tp->tp_firstwin;
-                                                 wp != NULL; wp = wp->w_next)
+       FOR_ALL_WINDOWS_IN_TAB(tp, wp)
        {
            if (wp->w_id == id)
            {
@@ -7159,7 +7154,7 @@ win_id2win(typval_T *argvars)
     int            nr = 1;
     int            id = get_tv_number(&argvars[0]);
 
-    for (wp = firstwin; wp != NULL; wp = wp->w_next)
+    FOR_ALL_WINDOWS(wp)
     {
        if (wp->w_id == id)
            return nr;
@@ -7175,9 +7170,7 @@ win_findbuf(typval_T *argvars, list_T *list)
     tabpage_T   *tp;
     int                bufnr = get_tv_number(&argvars[0]);
 
-    for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
-       for (wp = tp == curtab ? firstwin : tp->tp_firstwin;
-                                                 wp != NULL; wp = wp->w_next)
+    FOR_ALL_TAB_WINDOWS(tp, wp)
            if (wp->w_buffer->b_fnum == bufnr)
                list_append_number(list, wp->w_id);
 }
index cf7b46be9552a3ff38e634ff6bbec72aa13d2e22..fe59e1b604999de2a5bef01471b9e4f532af5b1e 100644 (file)
@@ -1319,7 +1319,7 @@ get_window(
 {
     win_T      *wp = NULL;     /* window filename is in */
 
-    for (wp = firstwin; wp != NULL; wp = W_NEXT(wp))
+    FOR_ALL_WINDOWS(wp)
        if (buf == wp->w_buffer)
            break;
     return wp;