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

Code before:
/// @param[out] err     Error details, if any
void nvim_win_set_config(Window window, Dict(win_config) *config, Error *err)
  FUNC_API_SINCE(6)
{
#define HAS_KEY_X(d, key) HAS_KEY(d, win_config, key)
  win_T *win = find_window_by_handle(window, err);
  if (!win) {
    return;
  }

  tabpage_T *win_tp = win_find_tabpage(win);
  bool was_split = !win->w_floating;
  bool has_split = HAS_KEY_X(config, split);
  bool has_vertical = HAS_KEY_X(config, vertical);
  // reuse old values, if not overridden
  WinConfig fconfig = win->w_config;

  bool to_split = config->relative.size == 0
                  && !(HAS_KEY_X(config, external) ? config->external : fconfig.external)
                  && (has_split || has_vertical || was_split);

  if (!parse_win_config(win, config, &fconfig, !was_split || to_split, err)) {
    return;
  }
  win_T *parent = config->win == 0 ? curwin : NULL;
  tabpage_T *parent_tp = parent ? win_find_tabpage(parent) : NULL;

  if (config->win > 0) {
    parent = find_window_by_handle(fconfig.window, err);
    if (!parent) {
      return;
    } else if (to_split && parent->w_floating) {
      api_set_error(err, kErrorTypeException, "Cannot split a floating window");
      return;
    }
    parent_tp = win_find_tabpage(parent);

    // Prevent autocmd window from being moved into another tabpage
    if (is_aucmd_win(win) && win_tp != parent_tp) {
      api_set_error(err, kErrorTypeException, "Cannot move autocmd win to another tabpage");
      return;
    }
  }

  if (was_split && !to_split) {
    if (!win_new_float(win, false, fconfig, err)) {
      return;
    }
    redraw_later(win, UPD_NOT_VALID);
  } else if (to_split) {
    WinSplit old_split = win_split_dir(win);

Review comment (suggestion):
```suggestion
  tabpage_T *parent_tp = config->win == 0 ? curtab : NULL;
```

Nit: If `parent` is not `NULL` here then it's `curwin`, so it must be in `curtab`; skips a call.
Probably also clearer to make the condition `config->win == 0` here too. (Subjective)

Code after:
/// @param[out] err     Error details, if any
void nvim_win_set_config(Window window, Dict(win_config) *config, Error *err)
  FUNC_API_SINCE(6)
{
#define HAS_KEY_X(d, key) HAS_KEY(d, win_config, key)
  win_T *win = find_window_by_handle(window, err);
  if (!win) {
    return;
  }

  tabpage_T *win_tp = win_find_tabpage(win);
  bool was_split = !win->w_floating;
  bool has_split = HAS_KEY_X(config, split);
  bool has_vertical = HAS_KEY_X(config, vertical);
  // reuse old values, if not overridden
  WinConfig fconfig = win->w_config;

  bool to_split = config->relative.size == 0
                  && !(HAS_KEY_X(config, external) ? config->external : fconfig.external)
                  && (has_split || has_vertical || was_split);

  if (!parse_win_config(win, config, &fconfig, !was_split || to_split, err)) {
    return;
  }
  win_T *parent = config->win == 0 ? curwin : NULL;
  tabpage_T *parent_tp = config->win == 0 ? curtab : NULL;

  if (config->win > 0) {
    parent = find_window_by_handle(fconfig.window, err);
    if (!parent) {
      return;
    } else if (to_split && parent->w_floating) {
      api_set_error(err, kErrorTypeException, "Cannot split a floating window");
      return;
    }
    parent_tp = win_find_tabpage(parent);

    // Prevent autocmd window from being moved into another tabpage
    if (is_aucmd_win(win) && win_tp != parent_tp) {
      api_set_error(err, kErrorTypeException, "Cannot move autocmd win to another tabpage");
      return;
    }
  }

  if (was_split && !to_split) {
    if (!win_new_float(win, false, fconfig, err)) {
      return;
    }
    redraw_later(win, UPD_NOT_VALID);
  } else if (to_split) {
    WinSplit old_split = win_split_dir(win);