diff --git a/nvim/.config/nvim/lua/plug/_format.lua b/nvim/.config/nvim/lua/plug/_format.lua index 815e837..85021e8 100644 --- a/nvim/.config/nvim/lua/plug/_format.lua +++ b/nvim/.config/nvim/lua/plug/_format.lua @@ -54,9 +54,12 @@ local formatters = { require('formatter').setup({logging = false, filetype = formatters}) +-- Format on save: -- gather filetypes to autocorrect for each activated formatter above -local filetype = "" -for k, _ in pairs(formatters) do filetype = filetype .. "," .. k end -augroup({ - {'FileType', filetype, 'autocmd', 'BufWritePost', '', 'FormatWrite'} -}, 'formatonsave') +for k, _ in pairs(formatters) do + vim.api.nvim_create_autocmd({"Filetype " .. k}, { + command = "autocmd BufWritePost FormatWrite", + desc = "Automatically format on write", + group = vim.api.nvim_create_augroup('formatonsave', {clear = true}) + }) +end diff --git a/nvim/.config/nvim/lua/plugins.lua b/nvim/.config/nvim/lua/plugins.lua index 770b1c0..a9ad28b 100644 --- a/nvim/.config/nvim/lua/plugins.lua +++ b/nvim/.config/nvim/lua/plugins.lua @@ -2,15 +2,16 @@ local install_path = vim.fn.stdpath("data") .. "/pack/packer/start/packer.nvim" if vim.fn.empty(vim.fn.glob(install_path)) > 0 then vim.cmd("!git clone https://github.com/wbthomason/packer.nvim " .. - install_path) + install_path) end -vim.api.nvim_exec([[ - augroup Packer - autocmd! - autocmd BufWritePost plugins.lua PackerCompile - augroup END -]], false) +-- Compile on plugin edits +vim.api.nvim_create_autocmd({ "BufWritePost" }, { + pattern = "plugins.lua", + command = "PackerCompile", + desc = "Compile plugins after editing plugin list", + group = vim.api.nvim_create_augroup('compilepackages', { clear = true }) +}) local use = require("packer").use require("packer").startup(function()