LunarVim/lua/core/formatter.lua

59 lines
1.3 KiB
Lua
Raw Normal View History

-- autoformat
if O.format_on_save then
require("lv-utils").define_augroups {
autoformat = {
{
"BufWritePost",
"*",
2021-07-10 20:45:43 +02:00
":silent FormatWrite",
},
},
}
end
2021-07-13 06:48:37 +02:00
-- -- check if formatter has been defined for the language or not
-- local function formatter_exists(lang_formatter)
-- if lang_formatter == nil then
-- return false
-- end
-- if lang_formatter.exe == nil or lang_formatter.args == nil then
-- return false
-- end
-- return true
-- end
-- returns default formatter for given language
2021-07-13 06:48:37 +02:00
-- local function formatter_return(lang_formatter)
-- return {
-- exe = lang_formatter.exe,
-- args = lang_formatter.args,
-- stdin = not (lang_formatter.stdin ~= nil),
-- }
-- end
-- fill a table like this -> {rust: {exe:"sth",args:{"a","b"},stdin=true},go: {}...}
2021-07-13 06:48:37 +02:00
-- local formatter_filetypes = {}
-- for k, v in pairs(O.lang) do
-- if formatter_exists(v.formatter) then
-- local keys = v.filetypes
-- if keys == nil then
-- keys = { k }
-- end
-- for _, l in pairs(keys) do
-- formatter_filetypes[l] = {
-- function()
-- return formatter_return(v.formatter)
-- end,
-- }
-- end
-- end
-- end
2021-07-13 06:48:37 +02:00
require("formatter").setup {}
if not O.format_on_save then
vim.cmd [[if exists('#autoformat#BufWritePost')
:autocmd! autoformat
endif]]
end