.config/nvim/lua/plugins/formatter.lua

Sat, 18 May 2024 10:56:07 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Sat, 18 May 2024 10:56:07 -0500
changeset 1168
52750027eff6
parent 1163
40367220022e
permissions
-rw-r--r--

simplify nvim-cmp setup

1163
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
1 return {
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
2 {
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
3 "stevearc/conform.nvim",
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
4 opts = {
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
5 formatters_by_ft = {
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
6 lua = { "stylua" },
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
7 mail = { "pandoc_markdown" },
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
8 markdown = { "pandoc_markdown" },
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
9 perl = { "perltidy" },
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
10 ruby = { { "standardrb", "rubocop" } },
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
11 sh = { "shfmt" },
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
12 sql = { "pg_format" },
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
13 -- LSP-handled:
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
14 -- elixir = { "mix" },
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
15 -- go = { "goimports", "gofumpt" },
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
16 },
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
17 formatters = {
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
18 pandoc_markdown = {
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
19 command = "pandoc",
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
20 args = { "-f", "markdown", "-t", "markdown" },
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
21 stdin = true,
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
22 },
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
23 shfmt = {
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
24 prepend_args = function(_, ctx)
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
25 return { "-i", vim.bo[ctx.buf].shiftwidth }
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
26 end,
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
27 },
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
28 perltidy = {
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
29 prepend_args = function(_, ctx)
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
30 return { "-i", vim.bo[ctx.buf].shiftwidth }
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
31 end,
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
32 },
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
33 },
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
34 format_on_save = function(bufnr)
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
35 local autoformat_filetypes = { "elixir", "go" }
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
36
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
37 if not vim.tbl_contains(autoformat_filetypes, vim.bo[bufnr].filetype) then
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
38 return
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
39 end
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
40
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
41 return {
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
42 timeout_ms = 500,
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
43 lsp_fallback = true,
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
44 }
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
45 end
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
46 },
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
47 },
40367220022e switch to conform.nvim
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
48 }

mercurial