diff --git a/fnl/plugins/conform.fnl b/fnl/plugins/conform.fnl new file mode 100644 index 0000000..dea99e3 --- /dev/null +++ b/fnl/plugins/conform.fnl @@ -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 :cf + 2 (fn [] + ((. (require :conform) :format) {:async true})) + :desc "Format code" + :mode [:n :v]} + {1 :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 :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]}]} diff --git a/lua/plugins/conform.lua b/lua/plugins/conform.lua index 42464b3..39c9096 100644 --- a/lua/plugins/conform.lua +++ b/lua/plugins/conform.lua @@ -1,76 +1,35 @@ -return { - "conform.nvim", - event = "BufWritePre", - cmd = "ConformInfo", - keys = { - { - "cf", - function() - require("conform").format({ async = true }) - end, - desc = "Format code", - mode = { "n", "v" }, - }, - { - "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" }, - }, - { - "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 = {{"cf", _4_, desc = "Format code", mode = {"n", "v"}}, {"ctf", _5_, desc = "Disable autoformat on save globally", mode = {"n", "v"}}, {"cbf", _7_, desc = "Disable autoformat on save buffer", mode = {"n", "v"}}}}