Mercurial > vim
comparison 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 |
comparison
equal
deleted
inserted
replaced
19887:d03edd8c7e2f | 19888:435726a03481 |
---|---|
233 AutoPatCmd *next; // chain of active apc-s for auto-invalidation | 233 AutoPatCmd *next; // chain of active apc-s for auto-invalidation |
234 }; | 234 }; |
235 | 235 |
236 static AutoPatCmd *active_apc_list = NULL; // stack of active autocommands | 236 static AutoPatCmd *active_apc_list = NULL; // stack of active autocommands |
237 | 237 |
238 // Macro to loop over all the patterns for an autocmd event | |
239 #define FOR_ALL_AUTOCMD_PATTERNS(event, ap) \ | |
240 for ((ap) = first_autopat[(int)(event)]; (ap) != NULL; (ap) = (ap)->next) | |
241 | |
238 /* | 242 /* |
239 * augroups stores a list of autocmd group names. | 243 * augroups stores a list of autocmd group names. |
240 */ | 244 */ |
241 static garray_T augroups = {0, 0, sizeof(char_u *), 10, NULL}; | 245 static garray_T augroups = {0, 0, sizeof(char_u *), 10, NULL}; |
242 #define AUGROUP_NAME(i) (((char_u **)augroups.ga_data)[i]) | 246 #define AUGROUP_NAME(i) (((char_u **)augroups.ga_data)[i]) |
454 | 458 |
455 // invalidate buflocals looping through events | 459 // invalidate buflocals looping through events |
456 for (event = (event_T)0; (int)event < (int)NUM_EVENTS; | 460 for (event = (event_T)0; (int)event < (int)NUM_EVENTS; |
457 event = (event_T)((int)event + 1)) | 461 event = (event_T)((int)event + 1)) |
458 // loop over all autocommand patterns | 462 // loop over all autocommand patterns |
459 for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next) | 463 FOR_ALL_AUTOCMD_PATTERNS(event, ap) |
460 if (ap->buflocal_nr == buf->b_fnum) | 464 if (ap->buflocal_nr == buf->b_fnum) |
461 { | 465 { |
462 au_remove_pat(ap); | 466 au_remove_pat(ap); |
463 if (p_verbose >= 6) | 467 if (p_verbose >= 6) |
464 { | 468 { |
517 int in_use = FALSE; | 521 int in_use = FALSE; |
518 | 522 |
519 for (event = (event_T)0; (int)event < (int)NUM_EVENTS; | 523 for (event = (event_T)0; (int)event < (int)NUM_EVENTS; |
520 event = (event_T)((int)event + 1)) | 524 event = (event_T)((int)event + 1)) |
521 { | 525 { |
522 for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next) | 526 FOR_ALL_AUTOCMD_PATTERNS(event, ap) |
523 if (ap->group == i && ap->pat != NULL) | 527 if (ap->group == i && ap->pat != NULL) |
524 { | 528 { |
525 give_warning((char_u *)_("W19: Deleting augroup that is still in use"), TRUE); | 529 give_warning((char_u *)_("W19: Deleting augroup that is still in use"), TRUE); |
526 in_use = TRUE; | 530 in_use = TRUE; |
527 event = NUM_EVENTS; | 531 event = NUM_EVENTS; |
1039 /* | 1043 /* |
1040 * Show or delete all patterns for an event. | 1044 * Show or delete all patterns for an event. |
1041 */ | 1045 */ |
1042 if (*pat == NUL) | 1046 if (*pat == NUL) |
1043 { | 1047 { |
1044 for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next) | 1048 FOR_ALL_AUTOCMD_PATTERNS(event, ap) |
1045 { | 1049 { |
1046 if (forceit) // delete the AutoPat, if it's in the current group | 1050 if (forceit) // delete the AutoPat, if it's in the current group |
1047 { | 1051 { |
1048 if (ap->group == findgroup) | 1052 if (ap->group == findgroup) |
1049 au_remove_pat(ap); | 1053 au_remove_pat(ap); |
2398 if (sfname != NULL) | 2402 if (sfname != NULL) |
2399 forward_slash(sfname); | 2403 forward_slash(sfname); |
2400 forward_slash(fname); | 2404 forward_slash(fname); |
2401 #endif | 2405 #endif |
2402 | 2406 |
2403 for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next) | 2407 FOR_ALL_AUTOCMD_PATTERNS(event, ap) |
2404 if (ap->pat != NULL && ap->cmds != NULL | 2408 if (ap->pat != NULL && ap->cmds != NULL |
2405 && (ap->buflocal_nr == 0 | 2409 && (ap->buflocal_nr == 0 |
2406 ? match_file_pat(NULL, &ap->reg_prog, | 2410 ? match_file_pat(NULL, &ap->reg_prog, |
2407 fname, sfname, tail, ap->allow_dirs) | 2411 fname, sfname, tail, ap->allow_dirs) |
2408 : buf != NULL && ap->buflocal_nr == buf->b_fnum | 2412 : buf != NULL && ap->buflocal_nr == buf->b_fnum |