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:
Victor Blanchard
2022-11-07 04:31:50 +01:00
committed by GitHub
parent 10fbda508c
commit d337814906
11 changed files with 116 additions and 0 deletions

View File

@@ -20,6 +20,9 @@ describe(':write', function()
os.remove('test_bkc_file.txt')
os.remove('test_bkc_link.txt')
os.remove('test_fifo')
os.remove('test/write/p_opt.txt')
os.remove('test/write')
os.remove('test')
os.remove(fname)
os.remove(fname_bak)
os.remove(fname_broken)
@@ -94,6 +97,30 @@ describe(':write', function()
fifo:close()
end)
it("++p creates missing parent directories", function()
eq(0, eval("filereadable('p_opt.txt')"))
command("write ++p p_opt.txt")
eq(1, eval("filereadable('p_opt.txt')"))
os.remove("p_opt.txt")
eq(0, eval("filereadable('p_opt.txt')"))
command("write ++p ./p_opt.txt")
eq(1, eval("filereadable('p_opt.txt')"))
os.remove("p_opt.txt")
eq(0, eval("filereadable('test/write/p_opt.txt')"))
command("write ++p test/write/p_opt.txt")
eq(1, eval("filereadable('test/write/p_opt.txt')"))
eq(('Vim(write):E32: No file name'), pcall_err(command, 'write ++p test_write/'))
if not iswin() then
eq(('Vim(write):E17: "'..funcs.fnamemodify('.', ':p:h')..'" is a directory'),
pcall_err(command, 'write ++p .'))
eq(('Vim(write):E17: "'..funcs.fnamemodify('.', ':p:h')..'" is a directory'),
pcall_err(command, 'write ++p ./'))
end
end)
it('errors out correctly', function()
if isCI('cirrus') then
pending('FIXME: cirrus')