src/nvim/fileio.c
/// Cleanup autocommands and patterns that have been deleted.
/// This is only done when not executing autocommands.
Cleanup autocommands and patterns that have been deleted.
This is only done when not executing autocommands.
Cleanup autocommands and patterns that have been deleted . This is only done when not executing autocommands .
static void au_cleanup(void)
{
  AutoPat     *ap, **prev_ap;
  AutoCmd     *ac, **prev_ac;
  event_T event;
  if (autocmd_busy || !au_need_clean) {
    return;
  }
  for (event = (event_T)0; (int)event < (int)NUM_EVENTS;
       event = (event_T)((int)event + 1)) {
    prev_ap = &(first_autopat[(int)event]);
    for (ap = *prev_ap; ap != NULL; ap = *prev_ap) {
      prev_ac = &(ap->cmds);
      bool has_cmd = false;
      for (ac = *prev_ac; ac != NULL; ac = *prev_ac) {
        if (ap->pat == NULL || ac->cmd == NULL) {
          *prev_ac = ac->next;
          xfree(ac->cmd);
          xfree(ac);
        } else {
          has_cmd = true;
          prev_ac = &(ac->next);
        }
      }
      if (ap->pat != NULL && !has_cmd) {
        au_remove_pat(ap);
      }
      if (ap->pat == NULL) {
        if (ap->next == NULL) {
          if (prev_ap == &(first_autopat[(int)event])) {
            last_autopat[(int)event] = NULL;
          } else {
            last_autopat[(int)event] = (AutoPat *)prev_ap;
          }
        }
        *prev_ap = ap->next;
        vim_regfree(ap->reg_prog);
        xfree(ap);
      } else {
        prev_ap = &(ap->next);
      }
    }
  }
  au_need_clean = false;
}
static void au_cleanup ( void ) { AutoPat * ap , * * prev_ap ; AutoCmd * ac , * * prev_ac ; event_T event ; if ( autocmd_busy || ! au_need_clean ) { return ; } for ( event = ( event_T ) 0 ; ( int ) event < ( int ) NUM_EVENTS ; event = ( event_T ) ( ( int ) event + 1 ) ) { prev_ap = & ( first_autopat [ ( int ) event ] ) ; for ( ap = * prev_ap ; ap != NULL ; ap = * prev_ap ) { prev_ac = & ( ap -> cmds ) ; bool has_cmd = false ; for ( ac = * prev_ac ; ac != NULL ; ac = * prev_ac ) { if ( ap -> pat == NULL || ac -> cmd == NULL ) { * prev_ac = ac -> next ; xfree ( ac -> cmd ) ; xfree ( ac ) ; } else { has_cmd = true ; prev_ac = & ( ac -> next ) ; } } if ( ap -> pat != NULL && ! has_cmd ) { au_remove_pat ( ap ) ; } if ( ap -> pat == NULL ) { if ( ap -> next == NULL ) { if ( prev_ap == & ( first_autopat [ ( int ) event ] ) ) { last_autopat [ ( int ) event ] = NULL ; } else { last_autopat [ ( int ) event ] = ( AutoPat * ) prev_ap ; } } * prev_ap = ap -> next ; vim_regfree ( ap -> reg_prog ) ; xfree ( ap ) ; } else { prev_ap = & ( ap -> next ) ; } } } au_need_clean = false ; }
Cleanup autocommands and patterns that have been deleted.
Cleanup autocommands and patterns that have been deleted .
// Loop over all events. // Loop over all autocommand patterns. // Loop over all commands for this pattern. // Remove the command if the pattern is to be deleted or when // the command has been marked for deletion. // Pattern was not marked for deletion, but all of its commands were. // So mark the pattern for deletion. // Remove the pattern if it has been marked for deletion. // this depends on the "next" field being the first in // the struct