49 lines
1.1 KiB
Lua
49 lines
1.1 KiB
Lua
-- C++ LuaSnip Snippets
|
|
|
|
local luasnip = require('luasnip')
|
|
luasnip.filetype_extend('cpp', { 'c' })
|
|
local snip = luasnip.snippet
|
|
local text = luasnip.text_node
|
|
local ins = luasnip.insert_node
|
|
local dyn = luasnip.dynamic_node
|
|
local node = luasnip.snippet_node
|
|
local key = require("luasnip.nodes.key_indexer").new_key
|
|
|
|
local snippets = {
|
|
|
|
snip('for', {
|
|
text('for ('),
|
|
ins(1, 'auto'),
|
|
text(' '),
|
|
ins(2, 'index'),
|
|
text(' '),
|
|
ins(3, '='),
|
|
dyn(4, function(args)
|
|
local choice = args[2][1]
|
|
if choice == '=' then -- index based for loop
|
|
local var = args[1][1]
|
|
return node(nil, {
|
|
text(' '),
|
|
ins(1, '0'),
|
|
text('; ' .. var .. ' < '),
|
|
ins(2, 'count'),
|
|
text('; '),
|
|
ins(3, var .. '++'),
|
|
})
|
|
elseif choice == ':' then -- range based for loop
|
|
return node(nil, {
|
|
text(' '),
|
|
ins(1, 'container')
|
|
})
|
|
end
|
|
return node(nil, {})
|
|
end, { 2, 3 }, key('var')),
|
|
text({ ') {', '\t' }),
|
|
ins(0, ''),
|
|
text({ '', '}' })
|
|
}),
|
|
|
|
}
|
|
|
|
return snippets
|