75 lines
1.7 KiB
Lua
75 lines
1.7 KiB
Lua
local shfmt = function()
|
|
local indent = 0 -- Assume tabs initially.
|
|
if vim.o.expandtab then
|
|
local shiftwidth = vim.opt.shiftwidth:get()
|
|
if shiftwidth == 0 then
|
|
indent = vim.o.tabstop
|
|
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 = function()
|
|
local icon = require("fschauen.util.icons").ui.Format
|
|
return {
|
|
{
|
|
"<leader>F",
|
|
require("fschauen.util.autoformat").toggle,
|
|
desc = icon .. " Toggle auto [F]ormat on write",
|
|
},
|
|
{
|
|
"<leader>=",
|
|
"<cmd>Format<cr>",
|
|
desc = icon .. " format file",
|
|
},
|
|
{
|
|
"<c-f>",
|
|
"<cmd>Format<cr>",
|
|
mode = "i",
|
|
desc = icon .. " [f]ormat file",
|
|
},
|
|
}
|
|
end,
|
|
|
|
opts = function()
|
|
local builtin = require("formatter.filetypes")
|
|
return {
|
|
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,
|
|
}
|