don't format small c macros
This commit is contained in:
parent
b6a5589d99
commit
85b431d6f9
@ -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
|
||||||
@ -59,6 +60,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 })
|
||||||
for _, cmd in ipairs{"InsertLeavePre", "BufWritePre"} do
|
for _, cmd in ipairs{"InsertLeavePre", "BufWritePre"} do
|
||||||
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user