60 lines
1.6 KiB
Lua
60 lines
1.6 KiB
Lua
local shfmt = function()
|
|
local indent = 0 -- Assume tabs initially.
|
|
if vim.opt.expandtab:get() then
|
|
local shiftwidth = vim.opt.shiftwidth:get()
|
|
if shiftwidth == 0 then
|
|
indent = vim.opt.tabstop:get()
|
|
else
|
|
indent = shiftwidth
|
|
end
|
|
end
|
|
|
|
return {
|
|
exe = "shfmt",
|
|
-- stylua: ignore start
|
|
args = {
|
|
"--indent", indent, -- 0 for tabs, >0 for number of spaces.
|
|
"--keep-padding", -- Keep column alignment paddings.
|
|
},
|
|
-- stylua: ignore end
|
|
stdin = true,
|
|
}
|
|
end
|
|
|
|
return {
|
|
"mhartington/formatter.nvim",
|
|
|
|
cmd = {
|
|
"Format",
|
|
"FormatLock",
|
|
"FormatWrite",
|
|
"FormatWriteLock",
|
|
},
|
|
|
|
keys = {
|
|
-- stylua: ignore start
|
|
{ "<leader>F", "<cmd>Format<cr>", desc = " Format file" },
|
|
{ "<leader>F", "<cmd>'<,'>Format<cr>", mode = "v", desc = " Format selection" },
|
|
-- stylua: ignore end
|
|
},
|
|
|
|
opts = function(_, opts)
|
|
local builtin = require("formatter.filetypes")
|
|
return vim.tbl_deep_extend("force", opts or {}, {
|
|
filetype = {
|
|
-- stylua: ignore start
|
|
c = { builtin.c.clangformat },
|
|
cmake = { builtin.cmake.cmakeformat },
|
|
cpp = { builtin.cpp.clangformat },
|
|
cs = { builtin.cs.clangformat },
|
|
json = { builtin.cs.prettier },
|
|
lua = { builtin.lua.stylua },
|
|
markdown = { builtin.markdown.prettier },
|
|
python = {}, -- TODO: pick one
|
|
sh = { shfmt() },
|
|
zsh = { builtin.zsh.beautysh },
|
|
-- stylua: ignore end
|
|
},
|
|
})
|
|
end,
|
|
}
|