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

Code before:
    mainerr(_("--embed conflicts with -es/-Es/-l"), NULL, NULL);
  }

  // If there is a "+123" or "-c" command, set v:swapcommand to the first one.
  if (parmp->n_commands > 0) {
    const size_t swcmd_len = strlen(parmp->commands[0]) + 3;
    char *const swcmd = xmalloc(swcmd_len);
    snprintf(swcmd, swcmd_len, ":%s\r", parmp->commands[0]);
    set_vim_var_string(VV_SWAPCOMMAND, swcmd, -1);
    xfree(swcmd);
  }

  TIME_MSG("parsing arguments");
}

/// Initialize v:argf with the startup "file arguments".
///
/// This function collects the filenames that were passed on the command line
/// (and parsed into the global argument list by command_line_scan()) and stores
/// them in the read-only Vim variable v:argf.
///
/// Unlike v:argv, which contains the entire argv vector including options
/// (-u, --cmd, +cmd, etc.), v:argf contains only the raw file arguments.
/// Unlike argv(), v:argf is not affected by later :args commands or plugin
/// modifications; it is a snapshot of the original file args at startup.
static void set_argf_var(void)
{
  list_T *list = tv_list_alloc(kListLenMayKnow);

  for (int i = 0; i < GARGCOUNT; i++) {
    char *fname = alist_name(&GARGLIST[i]);
    if (fname != NULL) {
      tv_list_append_string(list, fname, -1);
    }
  }

  tv_list_set_lock(list, VAR_FIXED);
  set_vim_var_list(VV_ARGF, list);
}

// Many variables are in "params" so that we can pass them to invoked
// functions without a lot of arguments.  "argc" and "argv" are also
// copied, so that they can be changed.
static void init_params(mparm_T *paramp, int argc, char **argv)
{
  CLEAR_POINTER(paramp);
  paramp->argc = argc;
  paramp->argv = argv;
  paramp->use_debug_break_level = -1;
  paramp->window_count = -1;
  paramp->listen_addr = NULL;

Review comment (suggestion):
We probably should expand the filename to an absolute path, since CWD can change after startup, which would make `v:argf` not very useful thereafter.

And need a test for that scenario.

Also need tests for the `--` case:

    nvim ... -- file1 file2

And need tests that check what happens if the user calls `:argadd` in a `-c` or `--cmd` option:

    nvim --cmd "argadd file1.txt" -c "argadd file2.txt"

Code after:
      argv_idx = 1;
    }
  }

  if (embedded_mode && (silent_mode || parmp->luaf)) {
    mainerr(_("--embed conflicts with -es/-Es/-l"), NULL, NULL);
  }

  // If there is a "+123" or "-c" command, set v:swapcommand to the first one.
  if (parmp->n_commands > 0) {
    const size_t swcmd_len = strlen(parmp->commands[0]) + 3;
    char *const swcmd = xmalloc(swcmd_len);
    snprintf(swcmd, swcmd_len, ":%s\r", parmp->commands[0]);
    set_vim_var_string(VV_SWAPCOMMAND, swcmd, -1);
    xfree(swcmd);
  }

  TIME_MSG("parsing arguments");
}

static void set_argf_var(void)
{
  list_T *list = tv_list_alloc(kListLenMayKnow);

  for (int i = 0; i < GARGCOUNT; i++) {
    char *fname = alist_name(&GARGLIST[i]);
    if (fname != NULL) {
      (void)vim_FullName(fname, NameBuff, sizeof(NameBuff), false);
      tv_list_append_string(list, NameBuff, -1);
    }
  }

  tv_list_set_lock(list, VAR_FIXED);
  set_vim_var_list(VV_ARGF, list);
}

// Many variables are in "params" so that we can pass them to invoked
// functions without a lot of arguments.  "argc" and "argv" are also
// copied, so that they can be changed.
static void init_params(mparm_T *paramp, int argc, char **argv)
{
  CLEAR_POINTER(paramp);
  paramp->argc = argc;
  paramp->argv = argv;
  paramp->use_debug_break_level = -1;
  paramp->window_count = -1;
  paramp->listen_addr = NULL;
  paramp->server_addr = NULL;
  paramp->remote = 0;
  paramp->luaf = NULL;
  paramp->lua_arg0 = -1;