Improve #include snippet for c/c++
This commit is contained in:
parent
0471dd67c4
commit
fad688fc15
@ -1,10 +1,13 @@
|
|||||||
# C LuaSnip Snippets
|
-- C LuaSnip Snippets
|
||||||
|
|
||||||
local luasnip = require('luasnip')
|
local luasnip = require('luasnip')
|
||||||
local snip = luasnip.snippet
|
local snippet = 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 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()
|
||||||
@ -13,20 +16,16 @@ local function getIncludeGuardName()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local snippets = {
|
local snippets = {
|
||||||
snip('#include', {
|
|
||||||
text('#include '),
|
|
||||||
insert(1, '<', { key = 'open' }),
|
|
||||||
insert(2, 'header'),
|
|
||||||
func(function(args)
|
|
||||||
if args[1][1] == '<' then
|
|
||||||
return '>'
|
|
||||||
else
|
|
||||||
return '"'
|
|
||||||
end
|
|
||||||
end, key('open')),
|
|
||||||
}),
|
|
||||||
|
|
||||||
snip('once', {
|
snippet('#include', {
|
||||||
|
text('#include '),
|
||||||
|
choice(1, {
|
||||||
|
snip(nil, { text('<'), restore(1, 'header'), text('>') }),
|
||||||
|
snip(nil, { text('"'), restore(1, 'header'), text('"') }),
|
||||||
|
}),
|
||||||
|
}, { stored = { ['header'] = insert(1, 'header') } }),
|
||||||
|
|
||||||
|
snippet('once', {
|
||||||
text('#ifndef '),
|
text('#ifndef '),
|
||||||
func(function(args)
|
func(function(args)
|
||||||
return args[1][1]
|
return args[1][1]
|
||||||
@ -34,7 +33,7 @@ local snippets = {
|
|||||||
text({ '', '#define ' }),
|
text({ '', '#define ' }),
|
||||||
insert(1, getIncludeGuardName(), { key = 'name' }),
|
insert(1, getIncludeGuardName(), { key = 'name' }),
|
||||||
-- FIXME: dynamic(1, function(_, _)
|
-- FIXME: dynamic(1, function(_, _)
|
||||||
-- return snip({}, {
|
-- return snip(nil, {
|
||||||
-- insert(1, getIncludeGuardName())
|
-- insert(1, getIncludeGuardName())
|
||||||
-- })
|
-- })
|
||||||
-- end, { key = "name" }),
|
-- end, { key = "name" }),
|
||||||
@ -45,6 +44,7 @@ local snippets = {
|
|||||||
return args[1][1]
|
return args[1][1]
|
||||||
end, key('name')),
|
end, key('name')),
|
||||||
}),
|
}),
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return snippets
|
return snippets
|
||||||
|
Loading…
x
Reference in New Issue
Block a user