Add C/C++ include guard snippet 'once'
This commit is contained in:
parent
dc78a25253
commit
2814270762
@ -7,6 +7,11 @@ local insert = luasnip.insert_node
|
||||
local func = luasnip.function_node
|
||||
local key = require("luasnip.nodes.key_indexer").new_key
|
||||
|
||||
local function getIncludeGuardName()
|
||||
local filename = vim.fn.expand('%'):gsub('[^%w_]', '_'):upper()
|
||||
return filename .. '_INCLUDED'
|
||||
end
|
||||
|
||||
local snippets = {
|
||||
snip('#include', {
|
||||
text('#include '),
|
||||
@ -20,6 +25,21 @@ local snippets = {
|
||||
end
|
||||
end, key('open')),
|
||||
}),
|
||||
|
||||
snip('once', {
|
||||
text('#ifndef '),
|
||||
func(function(args)
|
||||
return args[1][1]
|
||||
end, key('name')),
|
||||
text({ '', '#define ' }),
|
||||
insert(1, getIncludeGuardName(), { key = 'name' }),
|
||||
text({ '', '', '', }),
|
||||
insert(0, ''),
|
||||
text({ '', '', '#endif // ' }),
|
||||
func(function(args)
|
||||
return args[1][1]
|
||||
end, key('name')),
|
||||
}),
|
||||
}
|
||||
|
||||
return snippets
|
||||
|
Loading…
x
Reference in New Issue
Block a user