aboutsummaryrefslogtreecommitdiffstats
path: root/doc/conform.txt
diff options
context:
space:
mode:
authorSteven Arcangeli <stevearc@stevearc.com>2023-09-13 23:52:55 -0700
committerSteven Arcangeli <stevearc@stevearc.com>2023-09-14 07:54:22 -0700
commit808c7e045d50dcb2ad512ea7fa94baf411654a95 (patch)
tree4f8bd202ed41fb7f96b850f8800dac75f1e542f1 /doc/conform.txt
parente9cc79fd723afccb8c0c16342b913fa6e96879b0 (diff)
doc: add some recipes to the documentation
Diffstat (limited to 'doc/conform.txt')
-rw-r--r--doc/conform.txt26
1 files changed, 8 insertions, 18 deletions
diff --git a/doc/conform.txt b/doc/conform.txt
index 0052326..bcae22f 100644
--- a/doc/conform.txt
+++ b/doc/conform.txt
@@ -27,6 +27,7 @@ OPTIONS *conform-option
},
-- If this is set, Conform will run the formatter on save.
-- It will pass the table to conform.format().
+ -- This can also be a function that returns the table.
format_on_save = {
-- I recommend these options. See :help conform.format for details.
lsp_fallback = true,
@@ -34,6 +35,7 @@ OPTIONS *conform-option
},
-- If this is set, Conform will run the formatter asynchronously after save.
-- It will pass the table to conform.format().
+ -- This can also be a function that returns the table.
format_after_save = {
lsp_fallback = true,
},
@@ -222,35 +224,23 @@ AUTOFORMAT *conform-autoforma
If you want more complex logic than the `format_on_save` option allows, you can
write it yourself using your own autocmd. For example:
>lua
- -- Format synchronously on save
- vim.api.nvim_create_autocmd("BufWritePre", {
- pattern = "*",
- callback = function(args)
+ -- if format_on_save is a function, it will be called during BufWritePre
+ require("conform").setup({
+ format_on_save = function(bufnr)
-- Disable autoformat on certain filetypes
local ignore_filetypes = { "sql", "java" }
- if vim.tbl_contains(ignore_filetypes, vim.bo[args.buf].filetype) then
+ if vim.tbl_contains(ignore_filetypes, vim.bo[bufnr].filetype) then
return
end
-- Disable with a global or buffer-local variable
- if vim.g.disable_autoformat or vim.b[args.buf].disable_autoformat then
+ if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
return
end
-- Disable autoformat for files in a certain path
- local bufname = vim.api.nvim_buf_get_name(args.buf)
+ local bufname = vim.api.nvim_buf_get_name(bufnr)
if bufname:match("/node_modules/") then
return
end
- require("conform").format({ timeout_ms = 500, lsp_fallback = true, bufnr = args.buf })
- end,
- })
-
- -- To eliminate the boilerplate, you can pass a function to format_on_save
- -- and it will be called during the BufWritePre callback.
- require("conform").setup({
- format_on_save = function(bufnr)
- if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
- return
- end
-- ...additional logic...
return { timeout_ms = 500, lsp_fallback = true }
end,