1
0
mirror of https://github.com/jdhao/nvim-config.git synced 2025-06-08 14:14:33 +02:00

Merge pull request #69 from jdhao/fix-autocmd

update the autocmd for saving a file
This commit is contained in:
jdhao 2022-08-20 00:52:33 -05:00 committed by GitHub
commit fdf8236fc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 6 deletions

View File

@ -133,7 +133,7 @@ augroup END
augroup auto_create_dir
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
" ref: https://vi.stackexchange.com/a/169/15292

View File

@ -15,13 +15,12 @@ function M.executable(name)
return false
end
function M.may_create_dir()
local fpath = fn.expand('<afile>')
local parent_dir = fn.fnamemodify(fpath, ":p:h")
local res = fn.isdirectory(parent_dir)
--- Create a dir if if does not exist
function M.may_create_dir(dir)
local res = fn.isdirectory(dir)
if res == 0 then
fn.mkdir(parent_dir, 'p')
fn.mkdir(dir, 'p')
end
end