my-nvim-config/laptop/plugin/conform.lua

38 lines
1 KiB
Lua
Raw Normal View History

2024-03-13 14:07:20 -05:00
local cnf = require("conform")
-- Setup autoformat on save, with async for slow formatters
local slow_format_filetypes = { "tex" }
cnf.setup({
formatters_by_ft = {
2024-03-23 03:27:49 -05:00
tex = { "latexindent" },
2024-03-13 14:07:20 -05:00
},
format_on_save = function(bufnr)
if slow_format_filetypes[vim.bo[bufnr].filetype] then
return
end
local function on_format(err)
if err and err:match("timeout$") then
slow_format_filetypes[vim.bo[bufnr].filetype] = true
end
end
return { timeout_ms = 200, lsp_fallback = true }, on_format
end,
format_after_save = function(bufnr)
if not slow_format_filetypes[vim.bo[bufnr].filetype] then
return
end
return { lsp_fallback = true }
end,
})
2024-03-23 03:27:49 -05:00
cnf.formatters.latexindent = {
2024-03-13 14:07:20 -05:00
-- command = "/usr/bin/latexindent",
prepend_args = { "-g", "/dev/null" }, -- Do not create an indent.log file
range_args = function(ctx)
return { "--lines", ctx.range.start[1] .. "-" .. ctx.range["end"][1] }
end,
}