aboutsummaryrefslogtreecommitdiff
path: root/autoload/write_mkpath.vim
blob: 0d3e35746f95f139dd0304b797685db764cd17e3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function! write_mkpath#(path) abort

  " Path exists, we don't need to do anything
  if isdirectory(a:path)
    return
  endif

  " If :write! was issued, we'll try to create the path; failing that, if
  " 'confirm' is enabled, and the user responds affirmatively to the prompt,
  " that will do, too.  Otherwise, we will allow the write to fail.
  if v:cmdbang
    let mkpath = 1
  elseif &confirm
    let mkpath = confirm('Create path '.dir.'?', "&Yes\n&No") == 1
  else
    let mkpath = 0
  endif

  " If we decided to attempt a path creation, do so
  if mkpath
    call mkdir(dir, 'p')
  endif

endfunction