Adds header guard for the current file using the include header guard generated by cpplint.
With packer
use("patwie/include-guard.nvim")
Setup is
include_guard = require("include-guard")
include_guard.setup({ copyright_holder = "your_name", add_copyright = true })
-- Example short cut ("w" as wrap)
r.nnoremap("<leader>ww", require("include-guard").AddIncludeGuardAndCopyright)
r.nnoremap("<leader>wg", require("include-guard").AddIncludeGuard)
r.nnoremap("<leader>wc", require("include-guard").UpdateCopyright)
The functions can be used in LuaSnip as well:
local present, include_guard = pcall(require, "include-guard")
if not present then
return
end
return {
-- Inserts the copyright string without leading comment.
s("cori", { f(function()
return include_guard.GetCopyrightString()
end) }),
-- Inserts the include guard for C++ header files.
s("inclg", {
f(function()
local s = include_guard.GetIncludeGuardString()
return { "#ifndef " .. s, "#define " .. s, "", "" }
end),
i(1, ""),
t("", ""),
f(function()
local s = include_guard.GetIncludeGuardString()
return { "", "", "#endif // " .. s }
end),
}),
}