From c0443dad35fc16c236a8aa610afff803462c386d Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Mon, 13 Jun 2022 19:30:43 +0200 Subject: [PATCH] nvim: Change remaining augroups to lua autocmds Changed formatting and plugin self-compilation to make use of the new neovim 0.7 autcmd api function. --- nvim/.config/nvim/lua/plug/_format.lua | 13 ++++++++----- nvim/.config/nvim/lua/plugins.lua | 15 ++++++++------- 2 files changed, 16 insertions(+), 12 deletions(-) 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()