From 60ba15bd72f0da554ef645bc2c7a50511b0224d9 Mon Sep 17 00:00:00 2001 From: srdusr Date: Fri, 1 Sep 2023 10:16:40 +0200 Subject: Create the directory if it does not exist for scratch() --- lua/user/mods.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lua/user') diff --git a/lua/user/mods.lua b/lua/user/mods.lua index 0b7f406..63b3ac0 100644 --- a/lua/user/mods.lua +++ b/lua/user/mods.lua @@ -614,12 +614,16 @@ end -- Function to create or toggle a scratch buffer function M.Scratch() - local scratch_dir = vim.fn.expand('~') + local scratch_dir = vim.fn.expand('~/notes/private') local scratch_date = os.date('%Y-%m-%d') - local scratch_file = 'notes-' .. scratch_date .. '.md' + local scratch_file = 'scratch-' .. scratch_date .. '.md' local scratch_buf = vim.fn.bufnr(scratch_file) local bufinfo = vim.fn.getbufinfo(scratch_buf) + -- Check if the directory exists, and create it if it doesn't + if vim.fn.isdirectory(scratch_dir) == 0 then + vim.fn.mkdir(scratch_dir, 'p') + end if scratch_buf == -1 then -- If the buffer doesn't exist, create it vim.cmd('vsplit ' .. scratch_dir .. '/' .. scratch_file) -- cgit v1.2.3