]> granicus.if.org Git - vim/commitdiff
patch 8.2.0500: using the same loop in many places v8.2.0500
authorBram Moolenaar <Bram@vim.org>
Thu, 2 Apr 2020 16:50:46 +0000 (18:50 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 2 Apr 2020 16:50:46 +0000 (18:50 +0200)
Problem:    Using the same loop in many places.
Solution:   Define more FOR_ALL macros. (Yegappan Lakshmanan, closes #5339)

34 files changed:
src/arglist.c
src/autocmd.c
src/buffer.c
src/change.c
src/channel.c
src/cmdexpand.c
src/diff.c
src/eval.c
src/evalbuffer.c
src/evalfunc.c
src/evalvars.c
src/evalwindow.c
src/ex_cmds2.c
src/filepath.c
src/globals.h
src/gui.c
src/if_py_both.h
src/if_ruby.c
src/insexpand.c
src/list.c
src/misc2.c
src/netbeans.c
src/popupwin.c
src/quickfix.c
src/screen.c
src/sign.c
src/spell.c
src/spellfile.c
src/spellsuggest.c
src/tag.c
src/terminal.c
src/userfunc.c
src/version.c
src/window.c

index ad404d8ae9e6bb438e74b325ce898cd414d7edcc..8e0f4d2e8e07ad1e9c44ca19c33da956cb743cf4 100644 (file)
@@ -1046,7 +1046,7 @@ do_arg_all(
            // Move the already present window to below the current window
            if (curwin->w_arg_idx != i)
            {
-               for (wpnext = firstwin; wpnext != NULL; wpnext = wpnext->w_next)
+               FOR_ALL_WINDOWS(wpnext)
                {
                    if (wpnext->w_arg_idx == i)
                    {
index dce23b8978191e3e4eaa1eec689a29e66a040da1..d6945f30625b214c5a0325abd9896210a54efb59 100644 (file)
@@ -235,6 +235,10 @@ struct AutoPatCmd_S
 
 static AutoPatCmd *active_apc_list = NULL; // stack of active autocommands
 
+// Macro to loop over all the patterns for an autocmd event
+#define FOR_ALL_AUTOCMD_PATTERNS(event, ap) \
+    for ((ap) = first_autopat[(int)(event)]; (ap) != NULL; (ap) = (ap)->next)
+
 /*
  * augroups stores a list of autocmd group names.
  */
@@ -456,7 +460,7 @@ aubuflocal_remove(buf_T *buf)
     for (event = (event_T)0; (int)event < (int)NUM_EVENTS;
                                            event = (event_T)((int)event + 1))
        // loop over all autocommand patterns
-       for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next)
+       FOR_ALL_AUTOCMD_PATTERNS(event, ap)
            if (ap->buflocal_nr == buf->b_fnum)
            {
                au_remove_pat(ap);
@@ -519,7 +523,7 @@ au_del_group(char_u *name)
        for (event = (event_T)0; (int)event < (int)NUM_EVENTS;
                                            event = (event_T)((int)event + 1))
        {
-           for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next)
+           FOR_ALL_AUTOCMD_PATTERNS(event, ap)
                if (ap->group == i && ap->pat != NULL)
                {
                    give_warning((char_u *)_("W19: Deleting augroup that is still in use"), TRUE);
@@ -1041,7 +1045,7 @@ do_autocmd_event(
      */
     if (*pat == NUL)
     {
-       for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next)
+       FOR_ALL_AUTOCMD_PATTERNS(event, ap)
        {
            if (forceit)  // delete the AutoPat, if it's in the current group
            {
@@ -2400,7 +2404,7 @@ has_autocmd(event_T event, char_u *sfname, buf_T *buf)
     forward_slash(fname);
 #endif
 
-    for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next)
+    FOR_ALL_AUTOCMD_PATTERNS(event, ap)
        if (ap->pat != NULL && ap->cmds != NULL
              && (ap->buflocal_nr == 0
                ? match_file_pat(NULL, &ap->reg_prog,
index cec33b0a45029840701fcdf21c71329ddf385956..8201157547c4e6791ac5811d3f0f90040ae95265 100644 (file)
@@ -2911,7 +2911,7 @@ buflist_setfpos(
 {
     wininfo_T  *wip;
 
-    for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next)
+    FOR_ALL_BUF_WININFO(buf, wip)
        if (wip->wi_win == win)
            break;
     if (wip == NULL)
@@ -3004,7 +3004,7 @@ find_wininfo(
 {
     wininfo_T  *wip;
 
-    for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next)
+    FOR_ALL_BUF_WININFO(buf, wip)
        if (wip->wi_win == curwin
 #ifdef FEAT_DIFF
                && (!skip_diff_buffer || !wininfo_other_tab_diff(wip))
@@ -3019,7 +3019,7 @@ find_wininfo(
 #ifdef FEAT_DIFF
        if (skip_diff_buffer)
        {
-           for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next)
+           FOR_ALL_BUF_WININFO(buf, wip)
                if (!wininfo_other_tab_diff(wip))
                    break;
        }
@@ -3132,7 +3132,7 @@ buflist_list(exarg_T *eap)
     if (vim_strchr(eap->arg, 't'))
     {
        ga_init2(&buflist, sizeof(buf_T *), 50);
-       for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+       FOR_ALL_BUFFERS(buf)
        {
            if (ga_grow(&buflist, 1) == OK)
                ((buf_T **)buflist.ga_data)[buflist.ga_len++] = buf;
index 3ee719812f0d20f0af8a5e86a15aa7de53529729..cfba90b3caee5b0b0510e22c2146b0bda0ccb4fd 100644 (file)
@@ -172,8 +172,7 @@ check_recorded_changes(
        linenr_T    prev_lnum;
        linenr_T    prev_lnume;
 
-       for (li = buf->b_recorded_changes->lv_first; li != NULL;
-                                                             li = li->li_next)
+       FOR_ALL_LIST_ITEMS(buf->b_recorded_changes, li)
        {
            prev_lnum = (linenr_T)dict_get_number(
                                      li->li_tv.vval.v_dict, (char_u *)"lnum");
@@ -362,8 +361,7 @@ invoke_listeners(buf_T *buf)
     argv[0].v_type = VAR_NUMBER;
     argv[0].vval.v_number = buf->b_fnum; // a:bufnr
 
-
-    for (li = buf->b_recorded_changes->lv_first; li != NULL; li = li->li_next)
+    FOR_ALL_LIST_ITEMS(buf->b_recorded_changes, li)
     {
        varnumber_T lnum;
 
index 4db40c9ddccc1b011c441cf1941a0c51e965e730..1dfb28f85468a534d554314dc23979e4642a4565 100644 (file)
@@ -61,6 +61,12 @@ static ch_part_T channel_part_send(channel_T *channel);
 static ch_part_T channel_part_read(channel_T *channel);
 static void free_job_options(jobopt_T *opt);
 
+#define FOR_ALL_CHANNELS(ch) \
+    for ((ch) = first_channel; (ch) != NULL; (ch) = (ch)->ch_next)
+
+#define FOR_ALL_JOBS(job) \
+    for ((job) = first_job; (job) != NULL; (job) = (job)->jv_next)
+
 // Whether a redraw is needed for appending a line to a buffer.
 static int channel_need_redraw = FALSE;
 
@@ -476,7 +482,7 @@ free_unused_channels_contents(int copyID, int mask)
     // point.
     ++safe_to_invoke_callback;
 
-    for (ch = first_channel; ch != NULL; ch = ch->ch_next)
+    FOR_ALL_CHANNELS(ch)
        if (!channel_still_useful(ch)
                                 && (ch->ch_copyID & mask) != (copyID & mask))
        {
@@ -520,8 +526,7 @@ channel_fd2channel(sock_T fd, ch_part_T *partp)
     ch_part_T  part;
 
     if (fd != INVALID_FD)
-       for (channel = first_channel; channel != NULL;
-                                                  channel = channel->ch_next)
+       FOR_ALL_CHANNELS(channel)
        {
            for (part = PART_SOCK; part < PART_IN; ++part)
                if (channel->ch_part[part].ch_fd == fd)
@@ -662,7 +667,7 @@ channel_gui_register_all(void)
 {
     channel_T *channel;
 
-    for (channel = first_channel; channel != NULL; channel = channel->ch_next)
+    FOR_ALL_CHANNELS(channel)
        channel_gui_register(channel);
 }
 
@@ -1569,7 +1574,7 @@ channel_buffer_free(buf_T *buf)
     channel_T  *channel;
     ch_part_T  part;
 
-    for (channel = first_channel; channel != NULL; channel = channel->ch_next)
+    FOR_ALL_CHANNELS(channel)
        for (part = PART_SOCK; part < PART_COUNT; ++part)
        {
            chanpart_T  *ch_part = &channel->ch_part[part];
@@ -1610,7 +1615,7 @@ channel_write_any_lines(void)
 {
     channel_T  *channel;
 
-    for (channel = first_channel; channel != NULL; channel = channel->ch_next)
+    FOR_ALL_CHANNELS(channel)
        channel_write_input(channel);
 }
 
@@ -1625,7 +1630,7 @@ channel_write_new_lines(buf_T *buf)
 
     // There could be more than one channel for the buffer, loop over all of
     // them.
-    for (channel = first_channel; channel != NULL; channel = channel->ch_next)
+    FOR_ALL_CHANNELS(channel)
     {
        chanpart_T  *in_part = &channel->ch_part[PART_IN];
        linenr_T    lnum;
@@ -2604,7 +2609,7 @@ append_to_buffer(buf_T *buffer, char_u *msg, channel_T *channel, ch_part_T part)
        // Find channels reading from this buffer and adjust their
        // next-to-read line number.
        buffer->b_write_to_channel = TRUE;
-       for (ch = first_channel; ch != NULL; ch = ch->ch_next)
+       FOR_ALL_CHANNELS(ch)
        {
            chanpart_T  *in_part = &ch->ch_part[PART_IN];
 
@@ -3180,7 +3185,7 @@ channel_free_all(void)
     channel_T *channel;
 
     ch_log(NULL, "channel_free_all()");
-    for (channel = first_channel; channel != NULL; channel = channel->ch_next)
+    FOR_ALL_CHANNELS(channel)
        channel_clear(channel);
 }
 #endif
@@ -3202,7 +3207,7 @@ channel_fill_wfds(int maxfd_arg, fd_set *wfds)
     int                maxfd = maxfd_arg;
     channel_T  *ch;
 
-    for (ch = first_channel; ch != NULL; ch = ch->ch_next)
+    FOR_ALL_CHANNELS(ch)
     {
        chanpart_T  *in_part = &ch->ch_part[PART_IN];
 
@@ -3227,7 +3232,7 @@ channel_fill_poll_write(int nfd_in, struct pollfd *fds)
     int                nfd = nfd_in;
     channel_T  *ch;
 
-    for (ch = first_channel; ch != NULL; ch = ch->ch_next)
+    FOR_ALL_CHANNELS(ch)
     {
        chanpart_T  *in_part = &ch->ch_part[PART_IN];
 
@@ -3821,7 +3826,7 @@ channel_handle_events(int only_keep_open)
     ch_part_T  part;
     sock_T     fd;
 
-    for (channel = first_channel; channel != NULL; channel = channel->ch_next)
+    FOR_ALL_CHANNELS(channel)
     {
        if (only_keep_open && !channel->ch_keep_open)
            continue;
@@ -3854,7 +3859,7 @@ channel_any_keep_open()
 {
     channel_T  *channel;
 
-    for (channel = first_channel; channel != NULL; channel = channel->ch_next)
+    FOR_ALL_CHANNELS(channel)
        if (channel->ch_keep_open)
            return TRUE;
     return FALSE;
@@ -4234,7 +4239,7 @@ channel_poll_setup(int nfd_in, void *fds_in, int *towait)
     struct     pollfd *fds = fds_in;
     ch_part_T  part;
 
-    for (channel = first_channel; channel != NULL; channel = channel->ch_next)
+    FOR_ALL_CHANNELS(channel)
     {
        for (part = PART_SOCK; part < PART_IN; ++part)
        {
@@ -4281,7 +4286,7 @@ channel_poll_check(int ret_in, void *fds_in)
     int                idx;
     chanpart_T *in_part;
 
-    for (channel = first_channel; channel != NULL; channel = channel->ch_next)
+    FOR_ALL_CHANNELS(channel)
     {
        for (part = PART_SOCK; part < PART_IN; ++part)
        {
@@ -4332,7 +4337,7 @@ channel_select_setup(
     fd_set     *wfds = wfds_in;
     ch_part_T  part;
 
-    for (channel = first_channel; channel != NULL; channel = channel->ch_next)
+    FOR_ALL_CHANNELS(channel)
     {
        for (part = PART_SOCK; part < PART_IN; ++part)
        {
@@ -4381,7 +4386,7 @@ channel_select_check(int ret_in, void *rfds_in, void *wfds_in)
     ch_part_T  part;
     chanpart_T *in_part;
 
-    for (channel = first_channel; channel != NULL; channel = channel->ch_next)
+    FOR_ALL_CHANNELS(channel)
     {
        for (part = PART_SOCK; part < PART_IN; ++part)
        {
@@ -5471,7 +5476,7 @@ job_any_running()
 {
     job_T      *job;
 
-    for (job = first_job; job != NULL; job = job->jv_next)
+    FOR_ALL_JOBS(job)
        if (job_still_useful(job))
        {
            ch_log(NULL, "GUI not forking because a job is running");
@@ -5570,7 +5575,7 @@ win32_build_cmd(list_T *l, garray_T *gap)
     char_u     *s;
 
     range_list_materialize(l);
-    for (li = l->lv_first; li != NULL; li = li->li_next)
+    FOR_ALL_LIST_ITEMS(l, li)
     {
        s = tv_get_string_chk(&li->li_tv);
        if (s == NULL)
@@ -5695,7 +5700,7 @@ free_unused_jobs_contents(int copyID, int mask)
     int                did_free = FALSE;
     job_T      *job;
 
-    for (job = first_job; job != NULL; job = job->jv_next)
+    FOR_ALL_JOBS(job)
        if ((job->jv_copyID & mask) != (copyID & mask)
                                                    && !job_still_useful(job))
        {
@@ -5781,7 +5786,7 @@ job_stop_on_exit(void)
 {
     job_T      *job;
 
-    for (job = first_job; job != NULL; job = job->jv_next)
+    FOR_ALL_JOBS(job)
        if (job->jv_status == JOB_STARTED && job->jv_stoponexit != NULL)
            mch_signal_job(job, job->jv_stoponexit);
 }
@@ -5795,7 +5800,7 @@ has_pending_job(void)
 {
     job_T          *job;
 
-    for (job = first_job; job != NULL; job = job->jv_next)
+    FOR_ALL_JOBS(job)
        // Only should check if the channel has been closed, if the channel is
        // open the job won't exit.
        if ((job->jv_status == JOB_STARTED && !job_channel_still_useful(job))
@@ -6589,7 +6594,7 @@ job_info_all(list_T *l)
     job_T      *job;
     typval_T   tv;
 
-    for (job = first_job; job != NULL; job = job->jv_next)
+    FOR_ALL_JOBS(job)
     {
        tv.v_type = VAR_JOB;
        tv.vval.v_job = job;
index 1f70dc58e4d1d4bb5ee321aeebb05164d3813bdf..4f9b3cad0c825500fea3443c149da8edc5e10fff 100644 (file)
@@ -2587,7 +2587,7 @@ ExpandUserList(
 
     ga_init2(&ga, (int)sizeof(char *), 3);
     // Loop over the items in the list.
-    for (li = retlist->lv_first; li != NULL; li = li->li_next)
+    FOR_ALL_LIST_ITEMS(retlist, li)
     {
        if (li->li_tv.v_type != VAR_STRING || li->li_tv.vval.v_string == NULL)
            continue;  // Skip non-string items and empty strings
index f9969045431459cef6fc6670b465d24e933d61c6..3d61d49d1cab1f7d17022b58a10afd3b7a64c7f0 100644 (file)
@@ -90,6 +90,9 @@ static int parse_diff_ed(char_u *line, linenr_T *lnum_orig, long *count_orig, li
 static int parse_diff_unified(char_u *line, linenr_T *lnum_orig, long *count_orig, linenr_T *lnum_new, long *count_new);
 static int xdiff_out(void *priv, mmbuffer_t *mb, int nbuf);
 
+#define FOR_ALL_DIFFBLOCKS_IN_TAB(tp, dp) \
+    for ((dp) = (tp)->tp_first_diff; (dp) != NULL; (dp) = (dp)->df_next)
+
 /*
  * Called when deleting or unloading a buffer: No longer make a diff with it.
  */
@@ -1857,7 +1860,7 @@ diff_check(win_T *wp, linenr_T lnum)
 #endif
 
     // search for a change that includes "lnum" in the list of diffblocks.
-    for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next)
+    FOR_ALL_DIFFBLOCKS_IN_TAB(curtab, dp)
        if (lnum <= dp->df_lnum[idx] + dp->df_count[idx])
            break;
     if (dp == NULL || lnum < dp->df_lnum[idx])
@@ -2069,7 +2072,7 @@ diff_set_topline(win_T *fromwin, win_T *towin)
     towin->w_topfill = 0;
 
     // search for a change that includes "lnum" in the list of diffblocks.
-    for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next)
+    FOR_ALL_DIFFBLOCKS_IN_TAB(curtab, dp)
        if (lnum <= dp->df_lnum[fromidx] + dp->df_count[fromidx])
            break;
     if (dp == NULL)
@@ -2374,7 +2377,7 @@ diff_find_change(
     }
 
     // search for a change that includes "lnum" in the list of diffblocks.
-    for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next)
+    FOR_ALL_DIFFBLOCKS_IN_TAB(curtab, dp)
        if (lnum <= dp->df_lnum[idx] + dp->df_count[idx])
            break;
     if (dp == NULL || diff_check_sanity(curtab, dp) == FAIL)
@@ -2508,7 +2511,7 @@ diff_infold(win_T *wp, linenr_T lnum)
     if (curtab->tp_first_diff == NULL)
        return TRUE;
 
-    for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next)
+    FOR_ALL_DIFFBLOCKS_IN_TAB(curtab, dp)
     {
        // If this change is below the line there can't be any further match.
        if (dp->df_lnum[idx] - diff_context > lnum)
@@ -3001,7 +3004,7 @@ diff_get_corresponding_line_int(
     if (curtab->tp_first_diff == NULL)         // no diffs today
        return lnum1;
 
-    for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next)
+    FOR_ALL_DIFFBLOCKS_IN_TAB(curtab, dp)
     {
        if (dp->df_lnum[idx1] > lnum1)
            return lnum1 - baseline;
@@ -3070,7 +3073,7 @@ diff_lnum_win(linenr_T lnum, win_T *wp)
        ex_diffupdate(NULL);            // update after a big change
 
     // search for a change that includes "lnum" in the list of diffblocks.
-    for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next)
+    FOR_ALL_DIFFBLOCKS_IN_TAB(curtab, dp)
        if (lnum <= dp->df_lnum[idx] + dp->df_count[idx])
            break;
 
index 78673759c16a3d5f5c68c54a2fb5cf25dee90aaa..6d666e61212f22890dac69f60891fc7a5a81cde7 100644 (file)
@@ -3973,11 +3973,11 @@ garbage_collect(int testing)
        abort = abort || set_ref_in_item(&aucmd_win->w_winvar.di_tv, copyID,
                                                                  NULL, NULL);
 #ifdef FEAT_PROP_POPUP
-    for (wp = first_popupwin; wp != NULL; wp = wp->w_next)
+    FOR_ALL_POPUPWINS(wp)
        abort = abort || set_ref_in_item(&wp->w_winvar.di_tv, copyID,
                                                                  NULL, NULL);
     FOR_ALL_TABPAGES(tp)
-       for (wp = tp->tp_first_popupwin; wp != NULL; wp = wp->w_next)
+       FOR_ALL_POPUPWINS_IN_TAB(tp, wp)
                abort = abort || set_ref_in_item(&wp->w_winvar.di_tv, copyID,
                                                                  NULL, NULL);
 #endif
index de6af6ad13c93d1cce9e352a13e33504f1b52ec1..2c20939bd4bf71b66f1c3eb7a9d87fa5fbd802d0 100644 (file)
@@ -117,7 +117,7 @@ find_win_for_curbuf(void)
 {
     wininfo_T *wip;
 
-    for (wip = curbuf->b_wininfo; wip != NULL; wip = wip->wi_next)
+    FOR_ALL_BUF_WININFO(curbuf, wip)
     {
        if (wip->wi_win != NULL)
        {
@@ -572,11 +572,11 @@ get_buffer_info(buf_T *buf)
     windows = list_alloc();
     if (windows != NULL)
     {
-       for (wp = first_popupwin; wp != NULL; wp = wp->w_next)
+       FOR_ALL_POPUPWINS(wp)
            if (wp->w_buffer == buf)
                list_append_number(windows, (varnumber_T)wp->w_id);
        FOR_ALL_TABPAGES(tp)
-           for (wp = tp->tp_first_popupwin; wp != NULL; wp = wp->w_next)
+           FOR_ALL_POPUPWINS_IN_TAB(tp, wp)
                if (wp->w_buffer == buf)
                    list_append_number(windows, (varnumber_T)wp->w_id);
 
index 6832bf171446bfadf0b5e344d98b99d5fff57d90..0db848cb359889bb0920b5ca8d237ad3f22630d6 100644 (file)
@@ -2831,8 +2831,7 @@ common_function(typval_T *argvars, typval_T *rettv, int is_funcref)
                    if (lv_len > 0)
                    {
                        range_list_materialize(list);
-                       for (li = list->lv_first; li != NULL;
-                                                        li = li->li_next)
+                       FOR_ALL_LIST_ITEMS(list, li)
                            copy_tv(&li->li_tv, &pt->pt_argv[i++]);
                    }
                }
@@ -5021,7 +5020,7 @@ f_inputlist(typval_T *argvars, typval_T *rettv)
 
     l = argvars[0].vval.v_list;
     range_list_materialize(l);
-    for (li = l->lv_first; li != NULL; li = li->li_next)
+    FOR_ALL_LIST_ITEMS(argvars[0].vval.v_list, li)
     {
        msg_puts((char *)tv_get_string(&li->li_tv));
        msg_putchar('\n');
index 35d038db374a3f17254e19435d8809e85be8359d..7e408864ff4dc082f3df53001dcccb86d0cc4803 100644 (file)
@@ -1698,7 +1698,7 @@ item_lock(typval_T *tv, int deep, int lock)
                    l->lv_lock &= ~VAR_LOCKED;
                if ((deep < 0 || deep > 1) && l->lv_first != &range_list_item)
                    // recursive: lock/unlock the items the List contains
-                   for (li = l->lv_first; li != NULL; li = li->li_next)
+                   FOR_ALL_LIST_ITEMS(l, li)
                        item_lock(&li->li_tv, deep - 1, lock);
            }
            break;
index 534a047e6998ec12f079491df6367ba0fdc30acd..ab4ba838f5a14b0a0a326cbaea350fb65d023823 100644 (file)
@@ -106,14 +106,14 @@ win_id2wp_tp(int id, tabpage_T **tpp)
 #ifdef FEAT_PROP_POPUP
     // popup windows are in separate lists
      FOR_ALL_TABPAGES(tp)
-        for (wp = tp->tp_first_popupwin; wp != NULL; wp = wp->w_next)
+        FOR_ALL_POPUPWINS_IN_TAB(tp, wp)
             if (wp->w_id == id)
             {
                 if (tpp != NULL)
                     *tpp = tp;
                 return wp;
             }
-    for (wp = first_popupwin; wp != NULL; wp = wp->w_next)
+    FOR_ALL_POPUPWINS(wp)
        if (wp->w_id == id)
        {
            if (tpp != NULL)
@@ -188,7 +188,7 @@ find_win_by_nr(
            if (wp->w_id == nr)
                return wp;
        // check global popup windows
-       for (wp = first_popupwin; wp != NULL; wp = wp->w_next)
+       FOR_ALL_POPUPWINS(wp)
            if (wp->w_id == nr)
                return wp;
 #endif
index bbaff391e4197650a41e19398e0ab8d7fb8bc287..59f04a59a89a23f963729f42008c37a958bf715d 100644 (file)
@@ -303,7 +303,7 @@ check_changed_any(
     // buffers in other tabs
     FOR_ALL_TABPAGES(tp)
        if (tp != curtab)
-           for (wp = tp->tp_firstwin; wp != NULL; wp = wp->w_next)
+           FOR_ALL_WINDOWS_IN_TAB(tp, wp)
                add_bufnum(bufnrs, &bufnum, wp->w_buffer->b_fnum);
 
     // any other buffer
@@ -477,7 +477,7 @@ ex_listdo(exarg_T *eap)
        // great speed improvement.
        save_ei = au_event_disable(",Syntax");
 
-       for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+       FOR_ALL_BUFFERS(buf)
            buf->b_flags &= ~BF_SYN_SET;
        buf = curbuf;
     }
index 49b814fab78f1068be7058086241d98ba9a6df0c..37455a25696d69c4bcb2acf79023041ef594754e 100644 (file)
@@ -1917,7 +1917,7 @@ f_writefile(typval_T *argvars, typval_T *rettv)
        if (list == NULL)
            return;
        range_list_materialize(list);
-       for (li = list->lv_first; li != NULL; li = li->li_next)
+       FOR_ALL_LIST_ITEMS(list, li)
            if (tv_get_string_chk(&li->li_tv) == NULL)
                return;
     }
index 290f07dd5e7c16e6b33b11b95c2cf1e2905703ac..ac48a793d1edf6236d2de5af6860f1da1b7d930e 100644 (file)
@@ -676,6 +676,11 @@ EXTERN win_T       *prevwin INIT(= NULL);  // previous window
        for ((wp) = ((tp) == curtab) \
                ? firstwin : (tp)->tp_firstwin; (wp); (wp) = (wp)->w_next)
 
+#define FOR_ALL_POPUPWINS(wp) \
+    for ((wp) = first_popupwin; (wp) != NULL; (wp) = (wp)->w_next)
+#define FOR_ALL_POPUPWINS_IN_TAB(tp, wp) \
+    for ((wp) = (tp)->tp_first_popupwin; (wp) != NULL; (wp) = (wp)->w_next)
+
 
 EXTERN win_T   *curwin;        // currently active window
 
@@ -716,6 +721,9 @@ EXTERN buf_T        *curbuf INIT(= NULL);   // currently active buffer
 
 #define FOR_ALL_BUFFERS(buf) for (buf = firstbuf; buf != NULL; buf = buf->b_next)
 
+#define FOR_ALL_BUF_WININFO(buf, wip) \
+    for ((wip) = (buf)->b_wininfo; (wip) != NULL; (wip) = (wip)->wi_next)
+
 // Iterate through all the signs placed in a buffer
 #define FOR_ALL_SIGNS_IN_BUF(buf, sign) \
        for (sign = buf->b_signlist; sign != NULL; sign = sign->se_next)
@@ -1469,6 +1477,9 @@ EXTERN disptick_T display_tick INIT(= 0);
 // Line in which spell checking wasn't highlighted because it touched the
 // cursor position in Insert mode.
 EXTERN linenr_T                spell_redraw_lnum INIT(= 0);
+
+#define FOR_ALL_SPELL_LANGS(slang) \
+    for ((slang) = first_lang; (slang) != NULL; (slang) = slang->sl_next)
 #endif
 
 #ifdef FEAT_CONCEAL
@@ -1822,3 +1833,6 @@ EXTERN int did_repeated_msg INIT(= 0);
 # define REPEATED_MSG_LOOKING      1
 # define REPEATED_MSG_SAFESTATE            2
 #endif
+
+#define FOR_ALL_LIST_ITEMS(l, li) \
+    for ((li) = (l)->lv_first; (li) != NULL; (li) = (li)->li_next)
index 85e4628e71d47ab00ccd04a9b4b4a157e4b32b87..2d6008146d90ae8cccc83c69bdb5b70b835bf0bb 100644 (file)
--- a/src/gui.c
+++ b/src/gui.c
@@ -4189,7 +4189,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 c4d82e7f710ecd2bfd171a3adda29f7c61aaa104..0d70de2309353c1396e7b4c79d391d5a7e88a26a 100644 (file)
@@ -786,7 +786,7 @@ VimToPython(typval_T *our_tv, int depth, PyObject *lookup_dict)
        }
 
        range_list_materialize(list);
-       for (curr = list->lv_first; curr != NULL; curr = curr->li_next)
+       FOR_ALL_LIST_ITEMS(list, curr)
        {
            if (!(newObj = VimToPython(&curr->li_tv, depth + 1, lookup_dict)))
            {
@@ -3035,7 +3035,7 @@ FunctionConstructor(PyTypeObject *subtype, PyObject *args, PyObject *kwargs)
                    return NULL;
                }
                curtv = argv;
-               for (li = argslist->lv_first; li != NULL; li = li->li_next)
+               FOR_ALL_LIST_ITEMS(argslist, li)
                    copy_tv(&li->li_tv, curtv++);
            }
            list_unref(argslist);
index 80481e7d24b20263d05f660f3f6f180c0839c529..9b6d388a3c22fa7c29b3d7a2d134c8ebae0921a6 100644 (file)
@@ -1147,7 +1147,7 @@ vim_to_ruby(typval_T *tv)
 
        if (list != NULL)
        {
-           for (curr = list->lv_first; curr != NULL; curr = curr->li_next)
+           FOR_ALL_LIST_ITEMS(list, curr)
                rb_ary_push(result, vim_to_ruby(&curr->li_tv));
        }
     }
index 0b2435f4ce55885f632992a9f824bad9823d29b2..259acb91a5bd31b36d395be4807781ea953e51ad 100644 (file)
@@ -2331,7 +2331,7 @@ ins_compl_add_list(list_T *list)
 
     // Go through the List with matches and add each of them.
     range_list_materialize(list);
-    for (li = list->lv_first; li != NULL; li = li->li_next)
+    FOR_ALL_LIST_ITEMS(list, li)
     {
        if (ins_compl_add_tv(&li->li_tv, dir) == OK)
            // if dir was BACKWARD then honor it just once
@@ -2513,7 +2513,7 @@ get_complete_info(list_T *what_list, dict_T *retdict)
     {
        what_flag = 0;
        range_list_materialize(what_list);
-       for (item = what_list->lv_first; item != NULL; item = item->li_next)
+       FOR_ALL_LIST_ITEMS(what_list, item)
        {
            char_u *what = tv_get_string(&item->li_tv);
 
index 918626e1690f548e4334a37d78bb41fbc39e42a1..a7f4d40f7ea2263786531f06420c5a20422a8a72 100644 (file)
@@ -1109,7 +1109,7 @@ write_list(FILE *fd, list_T *list, int binary)
     char_u     *s;
 
     range_list_materialize(list);
-    for (li = list->lv_first; li != NULL; li = li->li_next)
+    FOR_ALL_LIST_ITEMS(list, li)
     {
        for (s = tv_get_string(&li->li_tv); *s != NUL; ++s)
        {
@@ -1207,7 +1207,7 @@ f_list2str(typval_T *argvars, typval_T *rettv)
        else
            char2bytes = mb_char2bytes;
 
-       for (li = l->lv_first; li != NULL; li = li->li_next)
+       FOR_ALL_LIST_ITEMS(l, li)
        {
            buf[(*char2bytes)(tv_get_number(&li->li_tv), buf)] = NUL;
            ga_concat(&ga, buf);
@@ -1216,7 +1216,7 @@ f_list2str(typval_T *argvars, typval_T *rettv)
     }
     else if (ga_grow(&ga, list_len(l) + 1) == OK)
     {
-       for (li = l->lv_first; li != NULL; li = li->li_next)
+       FOR_ALL_LIST_ITEMS(l, li)
            ga_append(&ga, tv_get_number(&li->li_tv));
        ga_append(&ga, NUL);
     }
@@ -1579,7 +1579,7 @@ do_sort_uniq(typval_T *argvars, typval_T *rettv, int sort)
        if (sort)
        {
            // sort(): ptrs will be the list to sort
-           for (li = l->lv_first; li != NULL; li = li->li_next)
+           FOR_ALL_LIST_ITEMS(l, li)
            {
                ptrs[i].item = li;
                ptrs[i].idx = i;
index 864d1fd40b3a2817f348515c03bf94248dab338e..491818927596d9eb8274b10ae091be9be9e8ed7b 100644 (file)
@@ -4348,7 +4348,7 @@ build_argv_from_list(list_T *l, char ***argv, int *argc)
     if (*argv == NULL)
        return FAIL;
     *argc = 0;
-    for (li = l->lv_first; li != NULL; li = li->li_next)
+    FOR_ALL_LIST_ITEMS(l, li)
     {
        s = tv_get_string_chk(&li->li_tv);
        if (s == NULL)
index f55f388e8a472202c0931de78a1d259b6b12136f..4d79a2eafadd62343126ecde884e3eaa762fb575 100644 (file)
@@ -2982,7 +2982,7 @@ netbeans_is_guarded(linenr_T top, linenr_T bot)
     if (!NETBEANS_OPEN)
        return FALSE;
 
-    for (p = curbuf->b_signlist; p != NULL; p = p->se_next)
+    FOR_ALL_SIGNS_IN_BUF(curbuf, p)
        if (p->se_id >= GUARDEDOFFSET)
            for (lnum = top + 1; lnum < bot; lnum++)
                if (lnum == p->se_lnum)
@@ -3095,7 +3095,7 @@ netbeans_gutter_click(linenr_T lnum)
     if (!NETBEANS_OPEN)
        return;
 
-    for (p = curbuf->b_signlist; p != NULL; p = p->se_next)
+    FOR_ALL_SIGNS_IN_BUF(curbuf, p)
     {
        if (p->se_lnum == lnum && p->se_next && p->se_next->se_lnum == lnum)
        {
index 947dd91bc1c1c75926d2419e122063465fd47d71..3a0dcb96aaccdd3f4cef68280e0bb8b744e19071 100644 (file)
@@ -835,8 +835,7 @@ apply_general_options(win_T *wp, dict_T *dict)
            listitem_T *li;
 
            ok = TRUE;
-           for (li = di->di_tv.vval.v_list->lv_first; li != NULL;
-                                                             li = li->li_next)
+           FOR_ALL_LIST_ITEMS(di->di_tv.vval.v_list, li)
            {
                if (li->li_tv.v_type != VAR_LIST
                        || li->li_tv.vval.v_list == NULL
@@ -967,7 +966,7 @@ add_popup_strings(buf_T *buf, list_T *l)
     linenr_T    lnum = 0;
     char_u     *p;
 
-    for (li = l->lv_first; li != NULL; li = li->li_next)
+    FOR_ALL_LIST_ITEMS(l, li)
        if (li->li_tv.v_type == VAR_STRING)
        {
            p = li->li_tv.vval.v_string;
@@ -989,7 +988,7 @@ add_popup_dicts(buf_T *buf, list_T *l)
     dict_T     *dict;
 
     // first add the text lines
-    for (li = l->lv_first; li != NULL; li = li->li_next)
+    FOR_ALL_LIST_ITEMS(l, li)
     {
        if (li->li_tv.v_type != VAR_DICT)
        {
@@ -1022,7 +1021,7 @@ add_popup_dicts(buf_T *buf, list_T *l)
            plist = di->di_tv.vval.v_list;
            if (plist != NULL)
            {
-               for (pli = plist->lv_first; pli != NULL; pli = pli->li_next)
+               FOR_ALL_LIST_ITEMS(plist, pli)
                {
                    if (pli->li_tv.v_type != VAR_DICT)
                    {
@@ -2881,12 +2880,12 @@ f_popup_getoptions(typval_T *argvars, typval_T *rettv)
        {
            win_T *twp;
 
-            for (twp = tp->tp_first_popupwin; twp != NULL; twp = twp->w_next)
-                if (twp->w_id == id)
-                    break;
-            if (twp != NULL)
-                break;
-            ++i;
+           FOR_ALL_POPUPWINS_IN_TAB(tp, twp)
+               if (twp->w_id == id)
+                   break;
+           if (twp != NULL)
+               break;
+           ++i;
        }
        if (tp == NULL)
            i = -1;  // must be global
@@ -2954,9 +2953,9 @@ popup_reset_handled(int handled_flag)
 {
     win_T *wp;
 
-    for (wp = first_popupwin; wp != NULL; wp = wp->w_next)
+    FOR_ALL_POPUPWINS(wp)
        wp->w_popup_handled &= ~handled_flag;
-    for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next)
+    FOR_ALL_POPUPWINS_IN_TAB(curtab, wp)
        wp->w_popup_handled &= ~handled_flag;
 }
 
@@ -2975,7 +2974,7 @@ find_next_popup(int lowest, int handled_flag)
 
     found_zindex = lowest ? INT_MAX : 0;
     found_wp = NULL;
-    for (wp = first_popupwin; wp != NULL; wp = wp->w_next)
+    FOR_ALL_POPUPWINS(wp)
        if ((wp->w_popup_handled & handled_flag) == 0
                && (wp->w_popup_flags & POPF_HIDDEN) == 0
                && (lowest ? wp->w_zindex < found_zindex
@@ -2984,7 +2983,7 @@ find_next_popup(int lowest, int handled_flag)
            found_zindex = wp->w_zindex;
            found_wp = wp;
        }
-    for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next)
+    FOR_ALL_POPUPWINS_IN_TAB(curtab, wp)
        if ((wp->w_popup_handled & handled_flag) == 0
                && (wp->w_popup_flags & POPF_HIDDEN) == 0
                && (lowest ? wp->w_zindex < found_zindex
@@ -3157,7 +3156,7 @@ popup_update_mask(win_T *wp, int width, int height)
        return;
     cells = wp->w_popup_mask_cells;
 
-    for (lio = wp->w_popup_mask->lv_first; lio != NULL; lio = lio->li_next)
+    FOR_ALL_LIST_ITEMS(wp->w_popup_mask, lio)
     {
        int cols, cole;
        int lines, linee;
@@ -3215,7 +3214,7 @@ update_popup_transparent(win_T *wp, int val)
        int             lines, linee;
        int             col, line;
 
-       for (lio = wp->w_popup_mask->lv_first; lio != NULL; lio = lio->li_next)
+       FOR_ALL_LIST_ITEMS(wp->w_popup_mask, lio)
        {
            li = lio->li_tv.vval.v_list->lv_first;
            cols = tv_get_number(&li->li_tv);
@@ -3325,12 +3324,12 @@ may_update_popup_mask(int type)
 
     // Check if any popup window buffer has changed and if any popup connected
     // to a text property has become visible.
-    for (wp = first_popupwin; wp != NULL; wp = wp->w_next)
+    FOR_ALL_POPUPWINS(wp)
        if (wp->w_popup_flags & POPF_HIDDEN)
            popup_mask_refresh |= check_popup_unhidden(wp);
        else if (popup_need_position_adjust(wp))
            popup_mask_refresh = TRUE;
-    for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next)
+    FOR_ALL_POPUPWINS_IN_TAB(curtab, wp)
        if (wp->w_popup_flags & POPF_HIDDEN)
            popup_mask_refresh |= check_popup_unhidden(wp);
        else if (popup_need_position_adjust(wp))
@@ -3838,7 +3837,7 @@ popup_find_preview_window(void)
     win_T *wp;
 
     // Preview window popup is always local to tab page.
-    for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next)
+    FOR_ALL_POPUPWINS_IN_TAB(curtab, wp)
        if (wp->w_p_pvw)
            return wp;
     return NULL;
@@ -3854,7 +3853,7 @@ popup_find_info_window(void)
     win_T *wp;
 
     // info window popup is always local to tab page.
-    for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next)
+    FOR_ALL_POPUPWINS_IN_TAB(curtab, wp)
        if (wp->w_popup_flags & POPF_INFO)
            return wp;
     return NULL;
index f82a187166087d021b00e3dad7968ee80b4e5072..127811a6585c1ba4e087b623db8137f025444dc9 100644 (file)
@@ -6911,7 +6911,7 @@ qf_add_entries(
        qf_store_title(qfl, title);
     }
 
-    for (li = list->lv_first; li != NULL; li = li->li_next)
+    FOR_ALL_LIST_ITEMS(list, li)
     {
        if (li->li_tv.v_type != VAR_DICT)
            continue; // Skip non-dict items
index ad548d241fc76c0b530e62c8f37266cbf73ae77f..d73e7c6941404604c00ff05f904673ee9e173c0d 100644 (file)
@@ -2572,11 +2572,11 @@ retry:
        win_free_lsize(aucmd_win);
 #ifdef FEAT_PROP_POPUP
     // global popup windows
-    for (wp = first_popupwin; wp != NULL; wp = wp->w_next)
+    FOR_ALL_POPUPWINS(wp)
        win_free_lsize(wp);
     // tab-local popup windows
     FOR_ALL_TABPAGES(tp)
-       for (wp = tp->tp_first_popupwin; wp != NULL; wp = wp->w_next)
+       FOR_ALL_POPUPWINS_IN_TAB(tp, wp)
            win_free_lsize(wp);
 #endif
 
@@ -2614,7 +2614,7 @@ retry:
        outofmem = TRUE;
 #ifdef FEAT_PROP_POPUP
     // global popup windows
-    for (wp = first_popupwin; wp != NULL; wp = wp->w_next)
+    FOR_ALL_POPUPWINS(wp)
        if (win_alloc_lines(wp) == FAIL)
        {
            outofmem = TRUE;
@@ -2622,7 +2622,7 @@ retry:
        }
     // tab-local popup windows
     FOR_ALL_TABPAGES(tp)
-       for (wp = tp->tp_first_popupwin; wp != NULL; wp = wp->w_next)
+       FOR_ALL_POPUPWINS_IN_TAB(tp, wp)
            if (win_alloc_lines(wp) == FAIL)
            {
                outofmem = TRUE;
index 1964c83087ba56b2e8fcaedb42f7ce74a8fa500e..fb7d5698927cadb24d008f43a176e022675251c2 100644 (file)
@@ -57,6 +57,9 @@ static char *cmds[] = {
 # define SIGNCMD_LAST  6
 };
 
+#define FOR_ALL_SIGNS(sp)      \
+    for ((sp) = first_sign; (sp) != NULL; (sp) = (sp)->sn_next)
+
 static hashtab_T       sg_table;       // sign group (signgroup_T) hashtable
 static int             next_sign_id = 1; // next sign id in the global group
 
@@ -294,7 +297,7 @@ find_sign_by_typenr(int typenr)
 {
     sign_T     *sp;
 
-    for (sp = first_sign; sp != NULL; sp = sp->sn_next)
+    FOR_ALL_SIGNS(sp)
        if (sp->sn_typenr == typenr)
            return sp;
     return NULL;
@@ -308,7 +311,7 @@ sign_typenr2name(int typenr)
 {
     sign_T     *sp;
 
-    for (sp = first_sign; sp != NULL; sp = sp->sn_next)
+    FOR_ALL_SIGNS(sp)
        if (sp->sn_typenr == typenr)
            return sp->sn_name;
     return (char_u *)_("[Deleted]");
@@ -880,7 +883,7 @@ sign_find(char_u *name, sign_T **sp_prev)
 
     if (sp_prev != NULL)
        *sp_prev = NULL;
-    for (sp = first_sign; sp != NULL; sp = sp->sn_next)
+    FOR_ALL_SIGNS(sp)
     {
        if (STRCMP(sp->sn_name, name) == 0)
            break;
@@ -1153,7 +1156,7 @@ sign_place(
     if (sign_group != NULL && (*sign_group == '*' || *sign_group == '\0'))
        return FAIL;
 
-    for (sp = first_sign; sp != NULL; sp = sp->sn_next)
+    FOR_ALL_SIGNS(sp)
        if (STRCMP(sp->sn_name, sign_name) == 0)
            break;
     if (sp == NULL)
@@ -1830,7 +1833,7 @@ sign_gui_started(void)
 {
     sign_T     *sp;
 
-    for (sp = first_sign; sp != NULL; sp = sp->sn_next)
+    FOR_ALL_SIGNS(sp)
        if (sp->sn_icon != NULL)
            sp->sn_image = gui_mch_register_sign(sp->sn_icon);
 }
@@ -1911,7 +1914,7 @@ sign_get_image(
 {
     sign_T     *sp;
 
-    for (sp = first_sign; sp != NULL; sp = sp->sn_next)
+    FOR_ALL_SIGNS(sp)
        if (sp->sn_typenr == typenr)
            return sp->sn_image;
     return NULL;
@@ -1950,7 +1953,7 @@ get_nth_sign_name(int idx)
 
     // Complete with name of signs already defined
     current_idx = 0;
-    for (sp = first_sign; sp != NULL; sp = sp->sn_next)
+    FOR_ALL_SIGNS(sp)
        if (current_idx++ == idx)
            return sp->sn_name;
     return NULL;
@@ -2212,7 +2215,7 @@ sign_define_multiple(list_T *l, list_T *retlist)
     listitem_T *li;
     int                retval;
 
-    for (li = l->lv_first; li != NULL; li = li->li_next)
+    FOR_ALL_LIST_ITEMS(l, li)
     {
        retval = -1;
        if (li->li_tv.v_type == VAR_DICT)
@@ -2547,7 +2550,7 @@ f_sign_placelist(typval_T *argvars, typval_T *rettv)
     }
 
     // Process the List of sign attributes
-    for (li = argvars[0].vval.v_list->lv_first; li != NULL; li = li->li_next)
+    FOR_ALL_LIST_ITEMS(argvars[0].vval.v_list, li)
     {
        sign_id = -1;
        if (li->li_tv.v_type == VAR_DICT)
@@ -2569,7 +2572,7 @@ sign_undefine_multiple(list_T *l, list_T *retlist)
     listitem_T *li;
     int                retval;
 
-    for (li = l->lv_first; li != NULL; li = li->li_next)
+    FOR_ALL_LIST_ITEMS(l, li)
     {
        retval = -1;
        name = tv_get_string_chk(&li->li_tv);
@@ -2765,7 +2768,7 @@ f_sign_unplacelist(typval_T *argvars, typval_T *rettv)
        return;
     }
 
-    for (li = argvars[0].vval.v_list->lv_first; li != NULL; li = li->li_next)
+    FOR_ALL_LIST_ITEMS(argvars[0].vval.v_list, li)
     {
        retval = -1;
        if (li->li_tv.v_type == VAR_DICT)
index 5fdcc3adae3f4bc7051e628dac5df361c4cf232a..99e030f911d14dd217575447f2077824465eab99 100644 (file)
@@ -2031,7 +2031,7 @@ did_set_spelllang(win_T *wp)
                dont_use_region = TRUE;
 
            // Check if we loaded this language before.
-           for (slang = first_lang; slang != NULL; slang = slang->sl_next)
+           FOR_ALL_SPELL_LANGS(slang)
                if (fullpathcmp(lang, slang->sl_fname, FALSE, TRUE) == FPC_SAME)
                    break;
        }
@@ -2048,7 +2048,7 @@ did_set_spelllang(win_T *wp)
                dont_use_region = TRUE;
 
            // Check if we loaded this language before.
-           for (slang = first_lang; slang != NULL; slang = slang->sl_next)
+           FOR_ALL_SPELL_LANGS(slang)
                if (STRICMP(lang, slang->sl_name) == 0)
                    break;
        }
@@ -2083,7 +2083,7 @@ did_set_spelllang(win_T *wp)
        /*
         * Loop over the languages, there can be several files for "lang".
         */
-       for (slang = first_lang; slang != NULL; slang = slang->sl_next)
+       FOR_ALL_SPELL_LANGS(slang)
            if (filename ? fullpathcmp(lang, slang->sl_fname, FALSE, TRUE)
                                                                    == FPC_SAME
                         : STRICMP(lang, slang->sl_name) == 0)
@@ -2162,7 +2162,7 @@ did_set_spelllang(win_T *wp)
        }
 
        // Check if it was loaded already.
-       for (slang = first_lang; slang != NULL; slang = slang->sl_next)
+       FOR_ALL_SPELL_LANGS(slang)
            if (fullpathcmp(spf_name, slang->sl_fname, FALSE, TRUE)
                                                                == FPC_SAME)
                break;
index 9500813e08644e72a047f8f72a54e4f7894fb2f6..920e05194c2c05253dc9e675fd19ddbe42b404a4 100644 (file)
 #define CF_WORD                0x01
 #define CF_UPPER       0x02
 
+/*
+ * Loop through all the siblings of a node (including the node)
+ */
+#define FOR_ALL_NODE_SIBLINGS(node, np) \
+    for ((np) = (node); (np) != NULL; (np) = (np)->wn_sibling)
+
 static int set_spell_finish(spelltab_T *new_st);
 static int write_spell_prefcond(FILE *fd, garray_T *gap);
 static int read_region_section(FILE *fd, slang_T *slang, int len);
@@ -1737,7 +1743,7 @@ spell_reload_one(
     slang_T    *slang;
     int                didit = FALSE;
 
-    for (slang = first_lang; slang != NULL; slang = slang->sl_next)
+    FOR_ALL_SPELL_LANGS(slang)
     {
        if (fullpathcmp(fname, slang->sl_fname, FALSE, TRUE) == FPC_SAME)
        {
@@ -2081,7 +2087,7 @@ spell_clear_flags(wordnode_T *node)
 {
     wordnode_T *np;
 
-    for (np = node; np != NULL; np = np->wn_sibling)
+    FOR_ALL_NODE_SIBLINGS(node, np)
     {
        np->wn_u1.index = FALSE;
        spell_clear_flags(np->wn_child);
@@ -4427,7 +4433,7 @@ tree_add_word(
        {
            --node->wn_refs;
            copyprev = prev;
-           for (copyp = node; copyp != NULL; copyp = copyp->wn_sibling)
+           FOR_ALL_NODE_SIBLINGS(node, copyp)
            {
                // Allocate a new node and copy the info.
                np = get_wordnode(spin);
@@ -4618,7 +4624,7 @@ deref_wordnode(spellinfo_T *spin, wordnode_T *node)
 
     if (--node->wn_refs == 0)
     {
-       for (np = node; np != NULL; np = np->wn_sibling)
+       FOR_ALL_NODE_SIBLINGS(node, np)
        {
            if (np->wn_child != NULL)
                cnt += deref_wordnode(spin, np->wn_child);
@@ -4761,7 +4767,7 @@ node_compress(
      */
     node->wn_u1.hashkey[0] = len;
     nr = 0;
-    for (np = node; np != NULL; np = np->wn_sibling)
+    FOR_ALL_NODE_SIBLINGS(node, np)
     {
        if (np->wn_byte == NUL)
            // end node: use wn_flags, wn_region and wn_affixID
@@ -5252,7 +5258,7 @@ clear_node(wordnode_T *node)
     wordnode_T *np;
 
     if (node != NULL)
-       for (np = node; np != NULL; np = np->wn_sibling)
+       FOR_ALL_NODE_SIBLINGS(node, np)
        {
            np->wn_u1.index = 0;
            np->wn_u2.wnode = NULL;
@@ -5296,7 +5302,7 @@ put_node(
     node->wn_u1.index = idx;
 
     // Count the number of siblings.
-    for (np = node; np != NULL; np = np->wn_sibling)
+    FOR_ALL_NODE_SIBLINGS(node, np)
        ++siblingcount;
 
     // Write the sibling count.
@@ -5304,7 +5310,7 @@ put_node(
        putc(siblingcount, fd);                         // <siblingcount>
 
     // Write each sibling byte and optionally extra info.
-    for (np = node; np != NULL; np = np->wn_sibling)
+    FOR_ALL_NODE_SIBLINGS(node, np)
     {
        if (np->wn_byte == 0)
        {
@@ -5392,7 +5398,7 @@ put_node(
     newindex += siblingcount + 1;
 
     // Recursively dump the children of each sibling.
-    for (np = node; np != NULL; np = np->wn_sibling)
+    FOR_ALL_NODE_SIBLINGS(node, np)
        if (np->wn_byte != 0 && np->wn_child->wn_u2.wnode == node)
            newindex = put_node(fd, np->wn_child, newindex, regionmask,
                                                                  prefixtree);
@@ -5447,7 +5453,7 @@ spell_make_sugfile(spellinfo_T *spin, char_u *wfname)
      * of the code for the soundfolding stuff.
      * It might have been done already by spell_reload_one().
      */
-    for (slang = first_lang; slang != NULL; slang = slang->sl_next)
+    FOR_ALL_SPELL_LANGS(slang)
        if (fullpathcmp(wfname, slang->sl_fname, FALSE, TRUE) == FPC_SAME)
            break;
     if (slang == NULL)
@@ -5666,7 +5672,7 @@ sug_filltable(
     int                nr;
     int                prev_nr;
 
-    for (p = node; p != NULL; p = p->wn_sibling)
+    FOR_ALL_NODE_SIBLINGS(node, p)
     {
        if (p->wn_byte == NUL)
        {
index 267a4a58c502ce688c78faff53b3e650448e9e4d..b74d30ba3a5198ca45a13a6b65f216a59d5af12d 100644 (file)
@@ -887,7 +887,7 @@ spell_suggest_expr(suginfo_T *su, char_u *expr)
     if (list != NULL)
     {
        // Loop over the items in the list.
-       for (li = list->lv_first; li != NULL; li = li->li_next)
+       FOR_ALL_LIST_ITEMS(list, li)
            if (li->li_tv.v_type == VAR_LIST)
            {
                // Get the word and the score from the items.
index bf45b2100cbf5c4af4949eec9a354608088fd88c..dc4b9a57124b674a378d9d9fb571da7170e30740 100644 (file)
--- a/src/tag.c
+++ b/src/tag.c
@@ -1358,7 +1358,7 @@ find_tagfunc_tags(
     }
     taglist = rettv.vval.v_list;
 
-    for (item = taglist->lv_first; item != NULL; item = item->li_next)
+    FOR_ALL_LIST_ITEMS(taglist, item)
     {
        char_u          *mfp;
        char_u          *res_name, *res_fname, *res_cmd, *res_kind;
@@ -4191,7 +4191,7 @@ tagstack_push_items(win_T *wp, list_T *l)
     int                fnum;
 
     // Add one entry at a time to the tag stack
-    for (li = l->lv_first; li != NULL; li = li->li_next)
+    FOR_ALL_LIST_ITEMS(l, li)
     {
        if (li->li_tv.v_type != VAR_DICT || li->li_tv.vval.v_dict == NULL)
            continue;                           // Skip non-dict items
index 2ff697acfa0d05d3798e186367ce3924a44f091f..d7d23cc25cde9f93290af3d1376e588dad068a10 100644 (file)
@@ -183,6 +183,9 @@ static BOOL has_conpty = FALSE;
 #define MAX_ROW 999999     // used for tl_dirty_row_end to update all rows
 #define KEY_BUF_LEN 200
 
+#define FOR_ALL_TERMS(term)    \
+    for ((term) = first_term; (term) != NULL; (term) = (term)->tl_next)
+
 /*
  * Functions with separate implementation for MS-Windows and Unix-like systems.
  */
@@ -626,8 +629,7 @@ term_start(
        listitem_T      *item;
 
        ga_init2(&ga, 1, 100);
-       for (item = argvar->vval.v_list->lv_first;
-                                       item != NULL; item = item->li_next)
+       FOR_ALL_LIST_ITEMS(argvar->vval.v_list, item)
        {
            char_u *s = tv_get_string_chk(&item->li_tv);
            char_u *p;
@@ -1892,7 +1894,7 @@ term_check_timers(int next_due_arg, proftime_T *now)
     term_T  *term;
     int            next_due = next_due_arg;
 
-    for (term = first_term; term != NULL; term = term->tl_next)
+    FOR_ALL_TERMS(term)
     {
        if (term->tl_timer_set && !term->tl_normal_mode)
        {
@@ -2175,7 +2177,7 @@ term_paste_register(int prev_c UNUSED)
     if (l != NULL)
     {
        type = get_reg_type(c, &reglen);
-       for (item = l->lv_first; item != NULL; item = item->li_next)
+       FOR_ALL_LIST_ITEMS(l, item)
        {
            char_u *s = tv_get_string(&item->li_tv);
 #ifdef MSWIN
@@ -5701,7 +5703,7 @@ f_term_list(typval_T *argvars UNUSED, typval_T *rettv)
        return;
 
     l = rettv->vval.v_list;
-    for (tp = first_term; tp != NULL; tp = tp->tl_next)
+    FOR_ALL_TERMS(tp)
        if (tp != NULL && tp->tl_buffer != NULL)
            if (list_append_number(l,
                                   (varnumber_T)tp->tl_buffer->b_fnum) == FAIL)
@@ -6077,7 +6079,7 @@ term_send_eof(channel_T *ch)
 {
     term_T     *term;
 
-    for (term = first_term; term != NULL; term = term->tl_next)
+    FOR_ALL_TERMS(term)
        if (term->tl_job == ch->ch_job)
        {
            if (term->tl_eof_chars != NULL)
index 5f98f18154b4358c08f478e030f7a30b3097c486..62003a83a39df7a88d8339c5aed0de8d91828445 100644 (file)
@@ -792,7 +792,7 @@ free_funccal_contents(funccall_T *fc)
     vars_clear(&fc->l_avars.dv_hashtab);
 
     // Free the a:000 variables.
-    for (li = fc->l_varlist.lv_first; li != NULL; li = li->li_next)
+    FOR_ALL_LIST_ITEMS(&fc->l_varlist, li)
        clear_tv(&li->li_tv);
 
     free_funccal(fc);
@@ -851,7 +851,7 @@ cleanup_function_call(funccall_T *fc)
        free_fc = FALSE;
 
        // Make a copy of the a:000 items, since we didn't do that above.
-       for (li = fc->l_varlist.lv_first; li != NULL; li = li->li_next)
+       FOR_ALL_LIST_ITEMS(&fc->l_varlist, li)
            copy_tv(&li->li_tv, &li->li_tv);
     }
 
@@ -1640,7 +1640,7 @@ func_call(
     int                r = 0;
 
     range_list_materialize(l);
-    for (item = l->lv_first; item != NULL; item = item->li_next)
+    FOR_ALL_LIST_ITEMS(args->vval.v_list, item)
     {
        if (argc == MAX_FUNC_ARGS - (partial == NULL ? 0 : partial->pt_argc))
        {
index 4c5abd6df87efab5272507d42cecdbc098358bde..bb11730bec49357661c34532005e8d062126c1b7 100644 (file)
@@ -738,6 +738,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    500,
 /**/
     499,
 /**/
index 964f1ef6d7aee04b55ba7511d5131d238c607d84..7efe7b164a6d69c86642a37ab305b3720eb04ca0 100644 (file)
@@ -1428,10 +1428,10 @@ win_valid_popup(win_T *win UNUSED)
 #ifdef FEAT_PROP_POPUP
     win_T      *wp;
 
-    for (wp = first_popupwin; wp != NULL; wp = wp->w_next)
+    FOR_ALL_POPUPWINS(wp)
        if (wp == win)
            return TRUE;
-    for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next)
+    FOR_ALL_POPUPWINS_IN_TAB(curtab, wp)
        if (wp == win)
            return TRUE;
 #endif
@@ -1473,7 +1473,7 @@ win_valid_any_tab(win_T *win)
                return TRUE;
        }
 #ifdef FEAT_PROP_POPUP
-       for (wp = tp->tp_first_popupwin; wp != NULL; wp = wp->w_next)
+       FOR_ALL_POPUPWINS_IN_TAB(tp, wp)
            if (wp == win)
                return TRUE;
 #endif
@@ -2276,7 +2276,7 @@ close_windows(
     {
        nexttp = tp->tp_next;
        if (tp != curtab)
-           for (wp = tp->tp_firstwin; wp != NULL; wp = wp->w_next)
+           FOR_ALL_WINDOWS_IN_TAB(tp, wp)
                if (wp->w_buffer == buf
                    && !(wp->w_closing || wp->w_buffer->b_locked > 0))
                {
@@ -4785,7 +4785,7 @@ buf_jump_open_tab(buf_T *buf)
     FOR_ALL_TABPAGES(tp)
        if (tp != curtab)
        {
-           for (wp = tp->tp_firstwin; wp != NULL; wp = wp->w_next)
+           FOR_ALL_WINDOWS_IN_TAB(tp, wp)
                if (wp->w_buffer == buf)
                    break;
            if (wp != NULL)
@@ -4968,7 +4968,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_ALL_BUFFERS(buf)
-       for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next)
+       FOR_ALL_BUF_WININFO(buf, wip)
            if (wip->wi_win == wp)
                wip->wi_win = NULL;