mirror of
https://github.com/jdhao/nvim-config.git
synced 2025-06-08 14:14:33 +02:00
use lua for may_create_dir
This commit is contained in:
parent
6fd7155787
commit
146ef5d0b8
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user