Repository: neovim/neovim
File: src/nvim/autocmd.c (C)

Code before:
      prevwin = win_find_by_handle(aco->save_prevwin_handle);

      // In case the autocommand moves the cursor to a position that does not
      // exist in curbuf
      VIsual_active = aco->save_VIsual_active;
      check_cursor(curwin);
    }
  }

  VIsual_active = aco->save_VIsual_active;
  check_cursor(curwin);  // just in case lines got deleted
  if (VIsual_active) {
    check_pos(curbuf, &VIsual);
  }
}

/// Schedules an autocommand event, to be executed at the next event-loop tick.
///
/// @param event Event to schedule
/// @param fname filename, NULL or empty means use actual file name
/// @param fname_io Filename to use for <afile> on cmdline,
///                 NULL means use `fname`.
/// @param group Group ID or AUGROUP_ALL
/// @param buf Buffer for <abuf>
/// @param eap Ex command arguments
/// @param data Additional arbitrary data associated with the event
void aucmd_defer(event_T event, char *fname, char *fname_io, int group, buf_T *buf, exarg_T *eap,
                 Object *data)
{
  DeferredEvent *evdata = xmalloc(sizeof(DeferredEvent));
  evdata->event = event;
  evdata->fname = fname;
  evdata->fname_io = fname_io;
  evdata->group = group;
  evdata->buf = buf->handle;
  evdata->eap = eap;
  if (data) {
    evdata->data = xmalloc(sizeof(Object));
    *evdata->data = copy_object(*data, NULL);
  } else {
    evdata->data = NULL;
  }

  multiqueue_put(deferred_autocmd_events, deferred_event, evdata);
}

/// Execute a deferred autocommand event
static void deferred_event(void **argv)
{
  DeferredEvent *e = argv[0];
  event_T event = e->event;

Review comment (suggestion):
```suggestion
/// @param data Event-specific data. Will be copied, caller must free `data`. 
/// The `data` items will also be copied to `v:event`.
```

Code after:
      prevwin = win_find_by_handle(aco->save_prevwin_handle);

      // In case the autocommand moves the cursor to a position that does not
      // exist in curbuf
      VIsual_active = aco->save_VIsual_active;
      check_cursor(curwin);
    }
  }

  VIsual_active = aco->save_VIsual_active;
  check_cursor(curwin);  // just in case lines got deleted
  if (VIsual_active) {
    check_pos(curbuf, &VIsual);
  }
}

/// Schedules an autocommand event, to be executed at the next event-loop tick.
///
/// @param event Event to schedule
/// @param fname Name to use as `<amatch>` (the "pattern"). NULL/empty means use actual filename.
/// @param fname_io Filename to use for <afile> on cmdline, NULL means use `fname`.
/// @param group Group ID or AUGROUP_ALL
/// @param buf Buffer for <abuf>
/// @param eap Ex command arguments
/// @param data Event-specific data. Will be copied, caller must free `data`.
/// The `data` items will also be copied to `v:event`.
void aucmd_defer(event_T event, char *fname, char *fname_io, int group, buf_T *buf, exarg_T *eap,
                 Object *data)
{
  AutoCmdEvent *evdata = xmalloc(sizeof(AutoCmdEvent));
  evdata->event = event;
  evdata->fname = fname != NULL ? xstrdup(fname) : NULL;
  evdata->fname_io = fname_io != NULL ? xstrdup(fname_io) : NULL;
  evdata->group = group;
  evdata->buf = buf->handle;
  evdata->eap = eap;
  if (data) {
    evdata->data = xmalloc(sizeof(Object));
    *evdata->data = copy_object(*data, NULL);
  } else {
    evdata->data = NULL;
  }

  multiqueue_put(deferred_events, deferred_event, evdata);
}

/// Executes a deferred autocommand event.
static void deferred_event(void **argv)
{
  AutoCmdEvent *e = argv[0];
  event_T event = e->event;