From e0003847ba2f45ad0854f0b4202225e4346c8ddd Mon Sep 17 00:00:00 2001 From: Crony Akatsuki Date: Wed, 26 Feb 2025 11:52:05 +0100 Subject: [PATCH] feat: load additional autocommands. --- modules/home-manager/neovim.nix | 7 ++++++- modules/home-manager/nvim/autocommands.lua | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 modules/home-manager/nvim/autocommands.lua diff --git a/modules/home-manager/neovim.nix b/modules/home-manager/neovim.nix index 326c24b..6e7f10e 100644 --- a/modules/home-manager/neovim.nix +++ b/modules/home-manager/neovim.nix @@ -62,7 +62,10 @@ enableTreesitter = true; enableFormat = true; - lua.enable = true; + lua = { + enable = true; + lsp.lazydev.enable = true; + }; # python = { # enable = true; # format.type = "black-and-isort"; @@ -172,6 +175,8 @@ } ]; + extraLuaFiles = [./nvim/autocommands.lua]; + extraPlugins = with pkgs.vimPlugins; { harpoon = { package = harpoon2; diff --git a/modules/home-manager/nvim/autocommands.lua b/modules/home-manager/nvim/autocommands.lua new file mode 100644 index 0000000..2655fcb --- /dev/null +++ b/modules/home-manager/nvim/autocommands.lua @@ -0,0 +1,16 @@ +local autocmd = vim.api.nvim_create_autocmd +local function augroup(name) + return vim.api.nvim_create_augroup("crony_" .. name, { clear = true }) +end + +-- [[ 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, +})