summaryrefslogtreecommitdiff
path: root/lua/ache/plugins
diff options
context:
space:
mode:
authorache <ache@ache.one>2025-05-14 18:19:36 +0200
committerache <ache@ache.one>2025-05-14 18:19:36 +0200
commita3af6d6d97947d2c49962edf60751d2f3f6c2edf (patch)
treef1902f16aa4e5b9efa68c2fc4f37ec263f35ec4e /lua/ache/plugins
parentConfigure Lazy shortkeys (diff)
Configure formatting
Diffstat (limited to 'lua/ache/plugins')
-rw-r--r--lua/ache/plugins/formatting.lua86
1 files changed, 67 insertions, 19 deletions
diff --git a/lua/ache/plugins/formatting.lua b/lua/ache/plugins/formatting.lua
index 38910bf..8bad1ad 100644
--- a/lua/ache/plugins/formatting.lua
+++ b/lua/ache/plugins/formatting.lua
@@ -3,29 +3,75 @@
--]
return {
"stevearc/conform.nvim",
- enable = false,
+ enabled = true,
event = { "BufReadPre", "BufNewFile" },
- config = function()
- local conform = require("conform")
-
- conform.setup({
- formatters_by_ft = {
- javascript = { "prettier" },
- typescript = { "prettier" },
- svelte = { "prettier" },
- css = { "prettier" },
- html = { "prettier" },
- json = { "prettier" },
- yaml = { "prettier" },
- markdown = { "prettier" },
- lua = { "stylua" },
- python = { "isort", "black" },
- },
- format_on_save = {
+ opts = {
+ formatters_by_ft = {
+ javascript = { "prettier" },
+ typescript = { "prettier" },
+ svelte = { "prettier" },
+ css = { "prettier" },
+ html = { "prettier" },
+ json = { "prettier" },
+ yaml = { "prettier" },
+ markdown = { "prettier" },
+ lua = { "stylua" },
+ fish = { "fish_indent" },
+ sh = { "shfmt" },
+ python = function(bufnr)
+ if require("conform").get_formatter_info("ruff_format", bufnr).available then
+ return { "ruff_format" }
+ else
+ return { "isort", "black" }
+ end
+ end,
+ },
+ format_on_save = function(bufnr)
+ -- Disable with a global or buffer-local variable
+ if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
+ return
+ end
+ return {
lsp_fallback = true,
async = false,
tiemout_ms = 1000,
- },
+ }
+ end,
+ -- Conform will notify you when no formatters are available for the buffer
+ notify_on_error = true,
+ },
+ config = function(_, opts)
+ local conform = require("conform")
+
+ conform.setup(opts)
+
+ vim.api.nvim_create_user_command("FormatDisable", function(args)
+ if args.bang then
+ -- FormatDisable! will disable formatting just for this buffer
+ vim.b.disable_autoformat = true
+ else
+ vim.g.disable_autoformat = true
+ end
+ end, {
+ desc = "Disable autoformat-on-save",
+ bang = true,
+ })
+ vim.api.nvim_create_user_command("FormatEnable", function()
+ vim.b.disable_autoformat = false
+ vim.g.disable_autoformat = false
+ end, {
+ desc = "Re-enable autoformat-on-save",
+ })
+ vim.api.nvim_create_user_command("FormatToggle", function()
+ if vim.b.disable_autoformat then
+ vim.b.disable_autoformat = false
+ vim.g.disable_autoformat = false
+ else
+ vim.b.disable_autoformat = true
+ vim.g.disable_autoformat = true
+ end
+ end, {
+ desc = "Toggle autoformat-on-save",
})
vim.keymap.set({ "n", "v" }, "<leader>mp", function()
@@ -35,5 +81,7 @@ return {
tiemout_ms = 1000,
})
end, { desc = "Format file or range (in visual mode)" })
+
+ vim.keymap.set({ "n", "v" }, "<leader>uf", "<cmd>FormatToggle<CR>", { desc = "Toggle autoformat-on-save" })
end,
}