Compare commits

..

No commits in common. "3b79830ece04142a9f725049f4e98a879b40cf2c" and "0471dd67c43b8993aebe33a567fd57409adf9948" have entirely different histories.

View File

@ -1,14 +1,10 @@
-- C LuaSnip Snippets # C LuaSnip Snippets
local luasnip = require('luasnip') local luasnip = require('luasnip')
local snippet = luasnip.snippet local snip = luasnip.snippet
local text = luasnip.text_node local text = luasnip.text_node
local insert = luasnip.insert_node local insert = luasnip.insert_node
local func = luasnip.function_node local func = luasnip.function_node
local choice = luasnip.choice_node
local dynamic = luasnip.dynamic_node
local restore = luasnip.restore_node
local snip = luasnip.snippet_node
local key = require("luasnip.nodes.key_indexer").new_key local key = require("luasnip.nodes.key_indexer").new_key
local function getIncludeGuardName() local function getIncludeGuardName()
@ -17,34 +13,38 @@ local function getIncludeGuardName()
end end
local snippets = { local snippets = {
snip('#include', {
snippet('#include', {
text('#include '), text('#include '),
choice(1, { insert(1, '<', { key = 'open' }),
snip(nil, { text('<'), restore(1, 'header'), text('>') }), insert(2, 'header'),
snip(nil, { text('"'), restore(1, 'header'), text('"') }), func(function(args)
if args[1][1] == '<' then
return '>'
else
return '"'
end
end, key('open')),
}), }),
}, { stored = { ['header'] = insert(1, 'header') } }),
snippet('once', { snip('once', {
text('#ifndef '), text('#ifndef '),
func(function(opts) func(function(args)
return opts[1][1] return args[1][1]
end, key('guard')), end, key('name')),
text({ '', '#define ' }), text({ '', '#define ' }),
dynamic(1, function() insert(1, getIncludeGuardName(), { key = 'name' }),
return snip(nil, { -- FIXME: dynamic(1, function(_, _)
insert(1, getIncludeGuardName(), { key = 'guard' }), -- return snip({}, {
}) -- insert(1, getIncludeGuardName())
end), -- })
-- end, { key = "name" }),
text({ '', '', '', }), text({ '', '', '', }),
insert(0, ''), insert(0, ''),
text({ '', '', '#endif // ' }), text({ '', '', '#endif // ' }),
func(function(opts) func(function(args)
return opts[1][1] return args[1][1]
end, key('guard')), end, key('name')),
}, {}), }),
} }
return snippets return snippets