mirror of
https://github.com/neovim/neovim.git
synced 2025-10-05 01:16:31 +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:
@@ -9970,6 +9970,7 @@ static void f_writefile(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
bool binary = false;
|
||||
bool append = false;
|
||||
bool do_fsync = !!p_fs;
|
||||
bool mkdir_p = false;
|
||||
if (argvars[2].v_type != VAR_UNKNOWN) {
|
||||
const char *const flags = tv_get_string_chk(&argvars[2]);
|
||||
if (flags == NULL) {
|
||||
@@ -9985,6 +9986,8 @@ static void f_writefile(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
do_fsync = true; break;
|
||||
case 'S':
|
||||
do_fsync = false; break;
|
||||
case 'p':
|
||||
mkdir_p = true; break;
|
||||
default:
|
||||
// Using %s, p and not %c, *p to preserve multibyte characters
|
||||
semsg(_("E5060: Unknown flag: %s"), p);
|
||||
@@ -10004,6 +10007,7 @@ static void f_writefile(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
emsg(_("E482: Can't open file with an empty name"));
|
||||
} else if ((error = file_open(&fp, fname,
|
||||
((append ? kFileAppend : kFileTruncate)
|
||||
| (mkdir_p ? kFileMkDir : kFileCreate)
|
||||
| kFileCreate), 0666)) != 0) {
|
||||
semsg(_("E482: Can't open file %s for writing: %s"),
|
||||
fname, os_strerror(error));
|
||||
|
Reference in New Issue
Block a user