1
0

don't format small c macros

This commit is contained in:
Rokas Puzonas 2023-05-11 17:31:02 +03:00
parent b6a5589d99
commit 85b431d6f9

View File

@ -12,7 +12,7 @@ for id, name in ipairs(query.captures) do
capture_lookup[name] = id capture_lookup[name] = id
end end
local function formatMacros() local function format_macros()
local bufnr = vim.api.nvim_get_current_buf() local bufnr = vim.api.nvim_get_current_buf()
local winnr = vim.api.nvim_get_current_win() local winnr = vim.api.nvim_get_current_win()
@ -25,6 +25,7 @@ local function formatMacros()
local lines = vim.api.nvim_buf_get_lines(bufnr, start_line, end_line+1, false) local lines = vim.api.nvim_buf_get_lines(bufnr, start_line, end_line+1, false)
local tabstop = tonumber(vim.bo[bufnr].tabstop) or 8 local tabstop = tonumber(vim.bo[bufnr].tabstop) or 8
if #lines > 2 then
for i, line in ipairs(lines) do for i, line in ipairs(lines) do
lines[i] = line:match("^(.-)%s*[\\]?$") lines[i] = line:match("^(.-)%s*[\\]?$")
end end
@ -58,6 +59,7 @@ local function formatMacros()
vim.api.nvim_buf_set_lines(bufnr, start_line, end_line+1, false, lines) vim.api.nvim_buf_set_lines(bufnr, start_line, end_line+1, false, lines)
end end
end
end end
local group = vim.api.nvim_create_augroup("UpdateCMacro", { clear = true }) local group = vim.api.nvim_create_augroup("UpdateCMacro", { clear = true })
@ -66,7 +68,7 @@ for _, cmd in ipairs{"InsertLeavePre", "BufWritePre"} do
group = group, group = group,
pattern = {"*.c", "*.h", "*.cpp", "*.hpp", "*.cc"}, pattern = {"*.c", "*.h", "*.cpp", "*.hpp", "*.cc"},
callback = function (data) callback = function (data)
formatMacros() format_macros()
end end
}) })
end end