From 47fc214cd176d5244533de34a0f85aaeccd0d17e Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Thu, 13 Feb 2025 13:33:37 +0100 Subject: feat: Sync --- lua/gabrielgio/formatter.lua | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'lua/gabrielgio/formatter.lua') diff --git a/lua/gabrielgio/formatter.lua b/lua/gabrielgio/formatter.lua index ca0ebc7..bf882bc 100644 --- a/lua/gabrielgio/formatter.lua +++ b/lua/gabrielgio/formatter.lua @@ -2,6 +2,21 @@ local formatter = require("formatter") local go = require("formatter.filetypes.go") local util = require("formatter.util") +local function yamlfmt() + return { exe = "yamlfmt" } +end + +local function terraformfmt() + return { + exe = "terraform", + args = { + "fmt", + "-", + }, + stdin = true, + } +end + formatter.setup({ filetype = { nix = { require("formatter.filetypes.nix").alejandra }, @@ -9,31 +24,19 @@ formatter.setup({ fish = { require("formatter.filetypes.fish").fishindent }, javascript = { require("formatter.filetypes.javascript").prettier }, go = { go.gofumpt, go.goimports }, - terraform = { - function() - return { - exe = "terraform", - args = { - "fmt", - "-", - }, - stdin = true, - } - end, - }, - yaml = { - function() - return { exe = "yamlfmt" } - end, - }, + terraform = { terraformfmt }, + yaml = { yamlfmt }, }, ["*"] = { require("formatter.filetypes.any").remove_trailing_whitespace, }, }) -vim.api.nvim_create_augroup("__formatter__", { clear = true }) -vim.api.nvim_create_autocmd("BufWritePost", { +local augroup = vim.api.nvim_create_augroup +local autocmd = vim.api.nvim_create_autocmd + +augroup("__formatter__", { clear = true }) +autocmd("BufWritePost", { group = "__formatter__", command = ":FormatWrite", }) -- cgit v1.2.3