aboutsummaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-05-30 16:40:58 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-05-30 16:40:58 +1200
commit1fffa6426c1c511668ccf4f5d17a63e94536d5e9 (patch)
treee514dbac9d71fa3aa61d97b822b0cf828a69b87c /autoload
parentFirst version (diff)
downloadvim-write-mkpath-1fffa6426c1c511668ccf4f5d17a63e94536d5e9.tar.gz
vim-write-mkpath-1fffa6426c1c511668ccf4f5d17a63e94536d5e9.zip
Extend to respect 'confirm' if set
Diffstat (limited to 'autoload')
-rw-r--r--autoload/write_mkpath.vim21
1 files changed, 20 insertions, 1 deletions
diff --git a/autoload/write_mkpath.vim b/autoload/write_mkpath.vim
index 36d3501..94fe21a 100644
--- a/autoload/write_mkpath.vim
+++ b/autoload/write_mkpath.vim
@@ -1,5 +1,24 @@
function! write_mkpath#(path) abort
- if v:cmdbang && !isdirectory(a:path)
+
+ " 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 l:mkpath = 1
+ elseif &confirm
+ let l:mkpath = confirm('Create path '.a:path.'?', "&Yes\n&No") == 1
+ else
+ let l:mkpath = 0
+ endif
+
+ " If we decided to attempt a path creation, do so
+ if l:mkpath
call mkdir(a:path, 'p')
endif
+
endfunction