aboutsummaryrefslogtreecommitdiffstats
path: root/doc/conform.txt
diff options
context:
space:
mode:
authorSteven Arcangeli <stevearc@stevearc.com>2023-08-28 18:27:46 -0700
committerSteven Arcangeli <stevearc@stevearc.com>2023-08-28 18:27:46 -0700
commitd508ae8f46b5b41e2806b412311719a941167c1a (patch)
treee4d9244fd20cbe0dcda9ce3a4e524fca5ba3d6fc /doc/conform.txt
parente09ef2a6a3d0f987963bfef771b5af060183f849 (diff)
refactor!: remove ability for formatter list to disable autoformat
I realized that there are so, so many possible features people would want when configuring the autoformatter, but it's better to just code it up yourself rather than try to create a config language that can describe all possible logic. Also adding new docs to provide examples of more advanced autoformat logic.
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: