-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b17eb6
commit 7e904f4
Showing
4 changed files
with
379 additions
and
372 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,69 @@ | ||
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" | ||
}) | ||
|
||
local options = { | ||
lsp_fallback = true, | ||
|
||
formatters_by_ft = { | ||
lua = { | ||
"stylua" | ||
}, | ||
|
||
sh = { | ||
"shfmt" | ||
}, | ||
|
||
cpp = { | ||
"clang-format" | ||
}, | ||
|
||
c = { | ||
"clang-format" | ||
}, | ||
|
||
python = { | ||
"black" | ||
} | ||
}, | ||
|
||
format_on_save = function(bufnr) | ||
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then | ||
return | ||
end | ||
return { | ||
timeout_ms = 3000, | ||
lsp_fallback = true | ||
} | ||
end | ||
} | ||
|
||
return { | ||
"stevearc/conform.nvim", | ||
-- for users those who want auto-save conform + lazyloading! | ||
event = "BufWritePre", | ||
cmd = { | ||
"ConformInfo" | ||
}, | ||
config = function() | ||
require("conform").setup(options) | ||
end, | ||
"stevearc/conform.nvim", | ||
event = { | ||
"BufWritePre", | ||
}, | ||
cmd = { | ||
"ConformInfo", | ||
}, | ||
keys = { | ||
{ | ||
-- Customize or remove this keymap to your liking | ||
"<leader>fm", | ||
function() | ||
require("conform").format({ | ||
async = true, | ||
}) | ||
end, | ||
mode = "", | ||
desc = "Format buffer", | ||
}, | ||
}, | ||
-- This will provide type hinting with LuaLS | ||
---@module "conform" | ||
---@type conform.setupOpts | ||
opts = { | ||
-- Define your formatters | ||
formatters_by_ft = { | ||
lua = { | ||
"stylua", | ||
config = "~/.config/nvim/lua/stylua.toml", | ||
}, | ||
python = { | ||
-- "isort", | ||
"black", | ||
}, | ||
-- javascript = { "prettierd", "prettier", stop_after_first = true }, | ||
sh = { | ||
"shfmt", | ||
}, | ||
|
||
cpp = { | ||
"clang-format", | ||
}, | ||
|
||
-- Keymap | ||
vim.keymap.set("n", "<leader>fm", function() | ||
vim.lsp.buf.format { | ||
async = true | ||
} | ||
end, { | ||
desc = "Formating", | ||
silent = true | ||
}) | ||
c = { | ||
"clang-format", | ||
}, | ||
}, | ||
-- Set default options | ||
default_format_opts = { | ||
lsp_format = "fallback", | ||
}, | ||
-- Set up format-on-save | ||
format_on_save = { | ||
timeout_ms = 500, | ||
}, | ||
-- Customize formatters | ||
-- formatters = { | ||
-- shfmt = { | ||
-- prepend_args = { "-i", "2" }, | ||
-- }, | ||
-- }, | ||
}, | ||
init = function() | ||
-- If you want the formatexpr, here is the place to set it | ||
vim.o.formatexpr = | ||
"v:lua.require'conform'.formatexpr()" | ||
end, | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.