feat: fennelize conform config

This commit is contained in:
Youwen Wu 2025-02-01 14:26:47 -08:00
parent c30b76d62d
commit 74e58bf808
Signed by: youwen5
GPG key ID: 865658ED1FE61EC3
2 changed files with 108 additions and 76 deletions

73
fnl/plugins/conform.fnl Normal file
View file

@ -0,0 +1,73 @@
{1 :conform.nvim
:after (fn []
((. (require :conform) :setup) {:default_format_opts {:lsp_format :fallback}
:format_on_save (fn [bufnr]
(when (or vim.g.disable_autoformat
(. vim.b
bufnr
:disable_autoformat))
(lua "return "))
{:lsp_fallback true
:timeout_ms 500})
:formatters_by_ft {:c {1 :clang-format
:lsp_format :fallback}
:cpp {1 :clang-format
:lsp_format :fallback}
:fennel {1 :fnlfmt
:lsp_format :fallback}
:haskell {1 :fourmolu
2 :ormolu
:stop_after_first true}
:javascript {1 :prettierd
2 :prettier
:stop_after_first true}
:json {1 :prettierd
2 :prettier
:stop_after_first true}
:jsonc {1 :prettierd
2 :prettier
:stop_after_first true}
:jypescriptreact {1 :prettierd
2 :prettier
:stop_after_first true}
:lua [:stylua]
:nix [:nixfmt]
:python [:black]
:rust {1 :rustfmt
:lsp_format :fallback}
:svelte {1 :prettier
:lsp_format :fallback}
:tex [:latexindent]
:toml {1 :taplo
:stop_after_first true}
:typescript {1 :prettierd
2 :prettier
:stop_after_first true}
:typescriptreact {1 :prettierd
2 :prettier
:stop_after_first true}
:typst [:typstyle]
:yaml {1 :prettierd
2 :prettier
:stop_after_first true}}})
(set vim.o.formatexpr "v:lua.require'conform'.formatexpr()"))
:cmd :ConformInfo
:event :BufWritePre
:keys [{1 :<leader>cf
2 (fn []
((. (require :conform) :format) {:async true}))
:desc "Format code"
:mode [:n :v]}
{1 :<leader>ctf
2 (fn []
(if vim.g.disable_autoformat (set vim.g.disable_autoformat false)
(set vim.g.disable_autoformat true)))
:desc "Disable autoformat on save globally"
:mode [:n :v]}
{1 :<leader>cbf
2 (fn []
(if (. vim.b 0 :disable_autoformat)
(tset (. vim.b 0) :disable_autoformat false)
(tset (. vim.b 0) :disable_autoformat true)))
:desc "Disable autoformat on save buffer"
:mode [:n :v]}]}

111
lua/plugins/conform.lua generated
View file

@ -1,76 +1,35 @@
return {
"conform.nvim",
event = "BufWritePre",
cmd = "ConformInfo",
keys = {
{
"<leader>cf",
function()
require("conform").format({ async = true })
end,
desc = "Format code",
mode = { "n", "v" },
},
{
"<leader>ctf",
function()
if vim.g.disable_autoformat then
vim.g.disable_autoformat = false
else
vim.g.disable_autoformat = true
end
end,
desc = "Disable autoformat on save globally",
mode = { "n", "v" },
},
{
"<leader>cbf",
function()
if vim.b[0].disable_autoformat then
vim.b[0].disable_autoformat = false
else
vim.b[0].disable_autoformat = true
end
end,
desc = "Disable autoformat on save buffer",
mode = { "n", "v" },
},
},
after = function()
require("conform").setup({
format_on_save = function(bufnr)
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
return
end
return { timeout_ms = 500, lsp_fallback = true }
end,
default_format_opts = {
lsp_format = "fallback",
},
formatters_by_ft = {
lua = { "stylua" },
python = { "black" },
rust = { "rustfmt", lsp_format = "fallback" },
javascript = { "prettierd", "prettier", stop_after_first = true },
typescript = { "prettierd", "prettier", stop_after_first = true },
typescriptreact = { "prettierd", "prettier", stop_after_first = true },
jypescriptreact = { "prettierd", "prettier", stop_after_first = true },
nix = { "nixfmt" },
haskell = { "fourmolu", "ormolu", stop_after_first = true },
json = { "prettierd", "prettier", stop_after_first = true },
jsonc = { "prettierd", "prettier", stop_after_first = true },
toml = { "taplo", stop_after_first = true },
yaml = { "prettierd", "prettier", stop_after_first = true },
typst = { "typstyle" },
svelte = { "prettier", lsp_format = "fallback" },
tex = { "latexindent" },
cpp = { "clang-format", lsp_format = "fallback" },
c = { "clang-format", lsp_format = "fallback" },
fennel = { "fnlfmt", lsp_format = "fallback" },
},
})
vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
end,
}
-- [nfnl] Compiled from ./fnl/plugins/conform.fnl by https://github.com/Olical/nfnl, do not edit.
local function _1_()
local function _2_(bufnr)
if (vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat) then
return
else
end
return {lsp_fallback = true, timeout_ms = 500}
end
require("conform").setup({default_format_opts = {lsp_format = "fallback"}, format_on_save = _2_, formatters_by_ft = {c = {"clang-format", lsp_format = "fallback"}, cpp = {"clang-format", lsp_format = "fallback"}, fennel = {"fnlfmt", lsp_format = "fallback"}, haskell = {"fourmolu", "ormolu", stop_after_first = true}, javascript = {"prettierd", "prettier", stop_after_first = true}, json = {"prettierd", "prettier", stop_after_first = true}, jsonc = {"prettierd", "prettier", stop_after_first = true}, jypescriptreact = {"prettierd", "prettier", stop_after_first = true}, lua = {"stylua"}, nix = {"nixfmt"}, python = {"black"}, rust = {"rustfmt", lsp_format = "fallback"}, svelte = {"prettier", lsp_format = "fallback"}, tex = {"latexindent"}, toml = {"taplo", stop_after_first = true}, typescript = {"prettierd", "prettier", stop_after_first = true}, typescriptreact = {"prettierd", "prettier", stop_after_first = true}, typst = {"typstyle"}, yaml = {"prettierd", "prettier", stop_after_first = true}}})
vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
return nil
end
local function _4_()
return require("conform").format({async = true})
end
local function _5_()
if vim.g.disable_autoformat then
vim.g.disable_autoformat = false
return nil
else
vim.g.disable_autoformat = true
return nil
end
end
local function _7_()
if vim.b[0].disable_autoformat then
vim.b[0]["disable_autoformat"] = false
return nil
else
vim.b[0]["disable_autoformat"] = true
return nil
end
end
return {"conform.nvim", after = _1_, cmd = "ConformInfo", event = "BufWritePre", keys = {{"<leader>cf", _4_, desc = "Format code", mode = {"n", "v"}}, {"<leader>ctf", _5_, desc = "Disable autoformat on save globally", mode = {"n", "v"}}, {"<leader>cbf", _7_, desc = "Disable autoformat on save buffer", mode = {"n", "v"}}}}