diff src/autocmd.c @ 19888:435726a03481 v8.2.0500

patch 8.2.0500: using the same loop in many places Commit: https://github.com/vim/vim/commit/aeea72151c31d686bcbb7b06d895006d7363585c Author: Bram Moolenaar <Bram@vim.org> Date: Thu Apr 2 18:50:46 2020 +0200 patch 8.2.0500: using the same loop in many places Problem: Using the same loop in many places. Solution: Define more FOR_ALL macros. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/5339)
author Bram Moolenaar <Bram@vim.org>
date Thu, 02 Apr 2020 19:00:05 +0200
parents 8cbadf7fb9d4
children d9a2e5dcfd9f
line wrap: on
line diff
--- 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 *sfnam
     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,