aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Arcangeli <stevearc@stevearc.com>2023-09-15 21:02:54 -0700
committerSteven Arcangeli <stevearc@stevearc.com>2023-09-15 21:03:02 -0700
commita589750635fcc5bb52c7e572cd853446c2c63855 (patch)
tree1342f0dbf7583a20bcff7f2a8c331a280a69bcc2
parent705d36300138a6dc5eb902b336d8358bf500bebd (diff)
feat: '_' filetype to define fallback formatters
-rw-r--r--README.md8
-rw-r--r--doc/conform.txt8
-rw-r--r--lua/conform/init.lua13
-rw-r--r--scripts/options_doc.lua8
4 files changed, 30 insertions, 7 deletions
diff --git a/README.md b/README.md
index 71c122f..eceb89d 100644
--- a/README.md
+++ b/README.md
@@ -240,10 +240,14 @@ require("conform").setup({
python = { "isort", "black" },
-- Use a sub-list to run only the first available formatter
javascript = { { "prettierd", "prettier" } },
- -- Use the "*" filetype to run formatters on all files.
+ -- Use the "*" filetype to run formatters on all filetypes.
-- Note that if you use this, you may want to set lsp_fallback = "always"
-- (see :help conform.format)
- ["*"] = { "trim_whitespace" },
+ ["*"] = { "codespell" },
+ -- Use the "_" filetype to run formatters on all filetypes
+ -- that don't have other formatters configured. Again, you may want to
+ -- set lsp_fallback = "always" when using this value.
+ ["_"] = { "trim_whitespace" },
},
-- If this is set, Conform will run the formatter on save.
-- It will pass the table to conform.format().
diff --git a/doc/conform.txt b/doc/conform.txt
index 1787f2c..bb3d90d 100644
--- a/doc/conform.txt
+++ b/doc/conform.txt
@@ -20,10 +20,14 @@ OPTIONS *conform-option
python = { "isort", "black" },
-- Use a sub-list to run only the first available formatter
javascript = { { "prettierd", "prettier" } },
- -- Use the "*" filetype to run formatters on all files.
+ -- Use the "*" filetype to run formatters on all filetypes.
-- Note that if you use this, you may want to set lsp_fallback = "always"
-- (see :help conform.format)
- ["*"] = { "trim_whitespace" },
+ ["*"] = { "codespell" },
+ -- Use the "_" filetype to run formatters on all filetypes
+ -- that don't have other formatters configured. Again, you may want to
+ -- set lsp_fallback = "always" when using this value.
+ ["_"] = { "trim_whitespace" },
},
-- If this is set, Conform will run the formatter on save.
-- It will pass the table to conform.format().
diff --git a/lua/conform/init.lua b/lua/conform/init.lua
index 07c46a3..aadec4d 100644
--- a/lua/conform/init.lua
+++ b/lua/conform/init.lua
@@ -171,7 +171,7 @@ M.list_formatters_for_buffer = function(bufnr)
end
end
- table.insert(filetypes, "*")
+ table.insert(filetypes, "_")
for _, filetype in ipairs(filetypes) do
---@type conform.FormatterUnit[]
local ft_formatters = M.formatters_by_ft[filetype]
@@ -183,7 +183,18 @@ M.list_formatters_for_buffer = function(bufnr)
end
dedupe_formatters(ft_formatters, formatters)
+ break
+ end
+ end
+
+ local ft_formatters = M.formatters_by_ft["*"]
+ if ft_formatters then
+ -- support the old structure where formatters could be a subkey
+ if not vim.tbl_islist(ft_formatters) then
+ ---@diagnostic disable-next-line: undefined-field
+ ft_formatters = ft_formatters.formatters
end
+ dedupe_formatters(ft_formatters, formatters)
end
return formatters
diff --git a/scripts/options_doc.lua b/scripts/options_doc.lua
index af7b10c..bce6908 100644
--- a/scripts/options_doc.lua
+++ b/scripts/options_doc.lua
@@ -6,10 +6,14 @@ require("conform").setup({
python = { "isort", "black" },
-- Use a sub-list to run only the first available formatter
javascript = { { "prettierd", "prettier" } },
- -- Use the "*" filetype to run formatters on all files.
+ -- Use the "*" filetype to run formatters on all filetypes.
-- Note that if you use this, you may want to set lsp_fallback = "always"
-- (see :help conform.format)
- ["*"] = { "trim_whitespace" },
+ ["*"] = { "codespell" },
+ -- Use the "_" filetype to run formatters on all filetypes
+ -- that don't have other formatters configured. Again, you may want to
+ -- set lsp_fallback = "always" when using this value.
+ ["_"] = { "trim_whitespace" },
},
-- If this is set, Conform will run the formatter on save.
-- It will pass the table to conform.format().