summaryrefslogtreecommitdiff
path: root/src/autocmd.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-04-02 18:50:46 +0200
committerBram Moolenaar <Bram@vim.org>2020-04-02 18:50:46 +0200
commitaeea72151c31d686bcbb7b06d895006d7363585c (patch)
tree500d487503a1a82cecc8f2a3e9bf89b50638fe5a /src/autocmd.c
parentf10806b25090879fdc1a86cc0da2f4f34fd21921 (diff)
downloadvim-git-aeea72151c31d686bcbb7b06d895006d7363585c.tar.gz
patch 8.2.0500: using the same loop in many placesv8.2.0500
Problem: Using the same loop in many places. Solution: Define more FOR_ALL macros. (Yegappan Lakshmanan, closes #5339)
Diffstat (limited to 'src/autocmd.c')
-rw-r--r--src/autocmd.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/autocmd.c b/src/autocmd.c
index dce23b897..d6945f306 100644
--- a/src/autocmd.c
+++ b/src/autocmd.c
@@ -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,