mirror of
https://github.com/jdhao/nvim-config.git
synced 2025-06-08 14:14:33 +02:00
update the autocmd for saving a file
This commit is contained in:
parent
efa7b215e7
commit
085c8017d8
@ -133,7 +133,7 @@ augroup END
|
|||||||
|
|
||||||
augroup auto_create_dir
|
augroup auto_create_dir
|
||||||
autocmd!
|
autocmd!
|
||||||
autocmd BufWritePre * lua require('utils').may_create_dir()
|
autocmd BufWritePre * lua require('utils').may_create_dir(vim.fn.fnamemodify(vim.fn.expand('<afile>'), ":p:h"))
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
" ref: https://vi.stackexchange.com/a/169/15292
|
" ref: https://vi.stackexchange.com/a/169/15292
|
||||||
|
|||||||
@ -15,13 +15,12 @@ function M.executable(name)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.may_create_dir()
|
--- Create a dir if if does not exist
|
||||||
local fpath = fn.expand('<afile>')
|
function M.may_create_dir(dir)
|
||||||
local parent_dir = fn.fnamemodify(fpath, ":p:h")
|
local res = fn.isdirectory(dir)
|
||||||
local res = fn.isdirectory(parent_dir)
|
|
||||||
|
|
||||||
if res == 0 then
|
if res == 0 then
|
||||||
fn.mkdir(parent_dir, 'p')
|
fn.mkdir(dir, 'p')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user