Problem: Using the same loop in many places.
Solution: Define more FOR_ALL macros. (Yegappan Lakshmanan, closes #5339)
// 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)
{
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.
*/
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);
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);
*/
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
{
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,
{
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)
{
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))
#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;
}
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;
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");
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;
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;
// 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))
{
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)
{
channel_T *channel;
- for (channel = first_channel; channel != NULL; channel = channel->ch_next)
+ FOR_ALL_CHANNELS(channel)
channel_gui_register(channel);
}
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];
{
channel_T *channel;
- for (channel = first_channel; channel != NULL; channel = channel->ch_next)
+ FOR_ALL_CHANNELS(channel)
channel_write_input(channel);
}
// 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;
// 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];
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
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];
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];
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;
{
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;
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)
{
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)
{
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)
{
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)
{
{
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");
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)
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))
{
{
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);
}
{
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))
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;
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
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.
*/
#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])
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)
}
// 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)
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)
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;
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;
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
{
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)
{
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);
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++]);
}
}
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');
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;
#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)
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
// 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
// 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;
}
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;
}
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
#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)
// 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
# 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)
// 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;
}
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)))
{
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);
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));
}
}
// 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
{
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);
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)
{
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);
}
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);
}
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;
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)
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)
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)
{
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
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;
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)
{
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)
{
{
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
{
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;
}
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
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
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;
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);
// 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))
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;
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;
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
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
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;
}
// 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;
# 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
{
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;
{
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]");
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;
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)
{
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);
}
{
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;
// 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;
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)
}
// 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)
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);
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)
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;
}
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;
}
/*
* 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)
}
// 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;
#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);
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)
{
{
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);
{
--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);
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);
*/
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
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;
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.
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)
{
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);
* 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)
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)
{
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.
}
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;
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
#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.
*/
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;
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)
{
if (l != NULL)
{
type = get_reg_type(c, ®len);
- 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
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)
{
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)
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);
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);
}
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))
{
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 500,
/**/
499,
/**/
#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
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
{
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))
{
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)
// 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;