diff options
author | Jesse Luehrs <doy@tozt.net> | 2017-10-29 16:01:43 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2017-10-29 19:03:53 -0400 |
commit | d9fd53a62b8fe7698400610d81456e5e3d9461ef (patch) | |
tree | fb76c6f3a6da79ec38e693ecb10b346afe9557d6 /vim/plugin/dircreate.vim | |
parent | c8b741e677788b77357c47ee1573f9ffd636c368 (diff) | |
download | conf-d9fd53a62b8fe7698400610d81456e5e3d9461ef.tar.gz conf-d9fd53a62b8fe7698400610d81456e5e3d9461ef.zip |
pull a bunch of self-contained things out of my vimrc
Diffstat (limited to 'vim/plugin/dircreate.vim')
-rw-r--r-- | vim/plugin/dircreate.vim | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/vim/plugin/dircreate.vim b/vim/plugin/dircreate.vim new file mode 100644 index 0000000..11da7f9 --- /dev/null +++ b/vim/plugin/dircreate.vim @@ -0,0 +1,31 @@ +function! s:ensure_dir_exists() + let l:required_dir = expand("%:h") + if !isdirectory(l:required_dir) + if <SID>ask_quit("Directory '" . l:required_dir . "' doesn't exist.", "&Create it?") + return + endif + + try + call mkdir(l:required_dir, 'p') + catch + call <SID>ask_quit("Can't create '" . l:required_dir . "'", "&Continue anyway?") + endtry + endif +endfunction + +function! s:ask_quit(msg, proposed_action) + if confirm(a:msg, "&Quit?\n" . a:proposed_action) == 1 + if len(getbufinfo()) > 1 + silent bd + return 1 + else + exit + end + endif + return 0 +endfunction + +augroup dircreate + autocmd! + autocmd BufNewFile * call <SID>ensure_dir_exists() +augroup END |