aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjdhao <jdhao@hotmail.com>2022-01-13 20:27:48 +0800
committerjdhao <jdhao@hotmail.com>2022-01-13 20:27:48 +0800
commit146ef5d0b86ca777f0ecd4eb5982f8beb4ea6e12 (patch)
tree1c439c29473576c26080d72825afeb5d6be43c41
parent6fd71557872092d6585ae8ab86605b5573ad6061 (diff)
use lua for may_create_dir
-rw-r--r--autoload/utils.vim9
-rw-r--r--core/autocommands.vim2
-rw-r--r--lua/utils.lua10
3 files changed, 11 insertions, 10 deletions
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("<afile>"))
+ 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('<afile>')
+ 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