diff --git a/autoload/utils.vim b/autoload/utils.vim index 2fa692e..580c1cd 100644 --- a/autoload/utils.vim +++ b/autoload/utils.vim @@ -207,12 +207,3 @@ function! utils#add_pack(name) abort return l:status endfunction - -" Create the parent dir for current file if it does not exist -function! utils#may_create_dir(path) abort - let l:parent_dir = fnamemodify(a:path, ':p:h') - - if !isdirectory(l:parent_dir) - call mkdir(l:parent_dir, "p") - endif -endfunction diff --git a/core/autocommands.vim b/core/autocommands.vim index c3943da..d929637 100644 --- a/core/autocommands.vim +++ b/core/autocommands.vim @@ -121,5 +121,5 @@ augroup END augroup auto_create_dir autocmd! - autocmd BufWritePre * call utils#may_create_dir(expand("")) + autocmd BufWritePre * lua require('utils').may_create_dir() augroup END diff --git a/lua/utils.lua b/lua/utils.lua index a4c02f2..7deb322 100644 --- a/lua/utils.lua +++ b/lua/utils.lua @@ -14,4 +14,14 @@ function M.executable(name) return false end +function M.may_create_dir() + local fpath = vim.fn.expand('') + local parent_dir = vim.fn.fnamemodify(fpath, ":p:h") + local res = vim.fn.isdirectory(parent_dir) + + if res == 0 then + vim.fn.mkdir(parent_dir, 'p') + end +end + return M