From d508ae8f46b5b41e2806b412311719a941167c1a Mon Sep 17 00:00:00 2001 From: Steven Arcangeli Date: Mon, 28 Aug 2023 18:27:46 -0700 Subject: 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. --- doc/conform.txt | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'doc') 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: -- cgit v1.2.3-70-g09d2