summaryrefslogtreecommitdiffstats
path: root/doc/conform.txt
diff options
context:
space:
mode:
Diffstat (limited to 'doc/conform.txt')
-rw-r--r--doc/conform.txt29
1 files changed, 29 insertions, 0 deletions
diff --git a/doc/conform.txt b/doc/conform.txt
index 77266cf..f602580 100644
--- a/doc/conform.txt
+++ b/doc/conform.txt
@@ -6,6 +6,7 @@ CONTENTS *conform-content
1. Options |conform-options|
2. Api |conform-api|
3. Formatters |conform-formatters|
+ 4. Autoformat |conform-autoformat|
--------------------------------------------------------------------------------
OPTIONS *conform-options*
@@ -172,5 +173,33 @@ FORMATTERS *conform-formatter
`yapf` - Yet Another Python Formatter.
`zigfmt` - Reformat Zig source into canonical form.
+--------------------------------------------------------------------------------
+AUTOFORMAT *conform-autoformat*
+
+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
+ vim.api.nvim_create_autocmd("BufWritePre", {
+ pattern = "*",
+ callback = function(args)
+ -- Disable autoformat on certain filetypes
+ local ignore_filetypes = { "sql", "java" }
+ if vim.tbl_contains(ignore_filetypes, vim.bo[args.buf].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
+ return
+ end
+ -- Disable autoformat for files in a certain path
+ local bufname = vim.api.nvim_buf_get_name(args.buf)
+ if bufname:match("/node_modules/") then
+ return
+ end
+ require("conform").format({ timeout_ms = 500, lsp_fallback = true, buf = args.buf })
+ end,
+ })
+<
+
================================================================================
vim:tw=80:ts=2:ft=help:norl:syntax=help: