mirror of
https://github.com/neovim/neovim.git
synced 2025-09-30 23:18:33 +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:
@@ -71,6 +71,7 @@ int file_open(FileDescriptor *const ret_fp, const char *const fname, const int f
|
||||
FLAG(flags, kFileReadOnly, O_RDONLY, kFalse, wr != kTrue);
|
||||
#ifdef O_NOFOLLOW
|
||||
FLAG(flags, kFileNoSymlink, O_NOFOLLOW, kNone, true);
|
||||
FLAG(flags, kFileMkDir, O_CREAT|O_WRONLY, kTrue, !(flags & kFileCreateOnly));
|
||||
#endif
|
||||
#undef FLAG
|
||||
// wr is used for kFileReadOnly flag, but on
|
||||
@@ -78,6 +79,13 @@ int file_open(FileDescriptor *const ret_fp, const char *const fname, const int f
|
||||
// `error: variable ‘wr’ set but not used [-Werror=unused-but-set-variable]`
|
||||
(void)wr;
|
||||
|
||||
if (flags & kFileMkDir) {
|
||||
int mkdir_ret = os_file_mkdir((char *)fname, 0755);
|
||||
if (mkdir_ret < 0) {
|
||||
return mkdir_ret;
|
||||
}
|
||||
}
|
||||
|
||||
const int fd = os_open(fname, os_open_flags, mode);
|
||||
|
||||
if (fd < 0) {
|
||||
|
Reference in New Issue
Block a user