From 4f0da4f6dbda1f6c6dad13ef05e35d846e7e91f2 Mon Sep 17 00:00:00 2001 From: CronyAkatsuki Date: Sun, 24 Dec 2023 15:47:32 +0100 Subject: [PATCH] Add aditional autocmd's --- lua/crony/init.lua | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/lua/crony/init.lua b/lua/crony/init.lua index 5ac14b4..d83fa9c 100644 --- a/lua/crony/init.lua +++ b/lua/crony/init.lua @@ -2,12 +2,28 @@ require('crony.set') require('crony.map') require('crony.lazy') +local autocmd = vim.api.nvim_create_autocmd + +local function augroup(name) + return vim.api.nvim_create_augroup("crony_" .. name, { clear = true }) +end + -- [[ Highlight on yank ]] -local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true }) -vim.api.nvim_create_autocmd('TextYankPost', { +autocmd("TextYankPost", { + group = augroup("highlight_yank"), callback = function() vim.highlight.on_yank() end, - group = highlight_group, - pattern = '*', +}) + +-- [[ Auto create parent directory if it doesn't exist ]] +autocmd({ "BufWritePre" }, { + group = augroup("auto_create_dir"), + callback = function(event) + if event.match:match("^%w%w+://") then + return + end + local file = vim.loop.fs_realpath(event.match) or event.match + vim.fn.mkdir(vim.fn.fnamemodify(file, ":p:h"), "p") + end, })