diff options
| author | jdhao <jdhao@hotmail.com> | 2022-08-20 00:52:33 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-20 00:52:33 -0500 |
| commit | fdf8236fc26a20498b4b342cfc742c8482d95731 (patch) | |
| tree | 275d40b627bf60635f9f912ec34de3b5e2adf5c9 | |
| parent | efa7b215e7010de3d1d03cc3e4adbc5ca89f3b26 (diff) | |
| parent | 085c8017d8ed3c83d1f61306d6b42f460d2857bc (diff) | |
Merge pull request #69 from jdhao/fix-autocmd
update the autocmd for saving a file
| -rw-r--r-- | core/autocommands.vim | 2 | ||||
| -rw-r--r-- | lua/utils.lua | 9 |
2 files changed, 5 insertions, 6 deletions
diff --git a/core/autocommands.vim b/core/autocommands.vim index 70b40db..c0c01d2 100644 --- a/core/autocommands.vim +++ b/core/autocommands.vim @@ -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 diff --git a/lua/utils.lua b/lua/utils.lua index ae9e0e9..3312479 100644 --- a/lua/utils.lua +++ b/lua/utils.lua @@ -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 |
