mirror of
https://github.com/neovim/neovim.git
synced 2025-09-19 01:38:16 +00:00
feat: ":write ++p" creates parent dirs #20835
- `:write ++p foo/bar/baz.txt` should create parent directories `foo/bar/` if they do not exist - Note: `:foo ++…` is usually for options. No existing options have a single-char abbreviation (presumably by design), so it's safe to special-case `++p` here. - Same for `writefile(…, 'foo/bar/baz.txt', 'p')` - `BufWriteCmd` can see the ++p flag via `v:cmdarg`. closes #19884
This commit is contained in:
@@ -7067,6 +7067,9 @@ char *set_cmdarg(exarg_T *eap, char *oldarg)
|
||||
if (eap->bad_char != 0) {
|
||||
len += 7 + 4; // " ++bad=" + "keep" or "drop"
|
||||
}
|
||||
if (eap->mkdir_p != 0) {
|
||||
len += 4;
|
||||
}
|
||||
|
||||
const size_t newval_len = len + 1;
|
||||
char *newval = xmalloc(newval_len);
|
||||
@@ -7100,6 +7103,11 @@ char *set_cmdarg(exarg_T *eap, char *oldarg)
|
||||
snprintf(newval + strlen(newval), newval_len, " ++bad=%c",
|
||||
eap->bad_char);
|
||||
}
|
||||
|
||||
if (eap->mkdir_p) {
|
||||
snprintf(newval, newval_len, " ++p");
|
||||
}
|
||||
|
||||
vimvars[VV_CMDARG].vv_str = newval;
|
||||
return oldval;
|
||||
}
|
||||
|
Reference in New Issue
Block a user