mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 03:48:18 +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:
@@ -111,6 +111,26 @@ describe('writefile()', function()
|
||||
pcall_err(command, ('call writefile([42], %s)'):format(ddname_tail)))
|
||||
end)
|
||||
|
||||
it('writefile(..., "p") creates missing parent directories', function()
|
||||
os.remove(dname)
|
||||
eq(nil, read_file(dfname))
|
||||
eq(0, funcs.writefile({'abc', 'def', 'ghi'}, dfname, 'p'))
|
||||
eq('abc\ndef\nghi\n', read_file(dfname))
|
||||
os.remove(dfname)
|
||||
os.remove(dname)
|
||||
eq(nil, read_file(dfname))
|
||||
eq(0, funcs.writefile({'\na\nb\n'}, dfname, 'pb'))
|
||||
eq('\0a\0b\0', read_file(dfname))
|
||||
os.remove(dfname)
|
||||
os.remove(dname)
|
||||
eq('Vim(call):E32: No file name',
|
||||
pcall_err(command, ('call writefile([], "%s", "p")'):format(dfname .. '.d/')))
|
||||
eq(('Vim(call):E482: Can\'t open file ./ for writing: illegal operation on a directory'),
|
||||
pcall_err(command, 'call writefile([], "./", "p")'))
|
||||
eq(('Vim(call):E482: Can\'t open file . for writing: illegal operation on a directory'),
|
||||
pcall_err(command, 'call writefile([], ".", "p")'))
|
||||
end)
|
||||
|
||||
it('errors out with invalid arguments', function()
|
||||
write_file(fname, 'TEST')
|
||||
eq('Vim(call):E119: Not enough arguments for function: writefile',
|
||||
|
Reference in New Issue
Block a user