Skip to content

Instantly share code, notes, and snippets.

@lotusirous
Created January 16, 2022 08:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lotusirous/361f494193e0295cb70a0809ae782fee to your computer and use it in GitHub Desktop.
Save lotusirous/361f494193e0295cb70a0809ae782fee to your computer and use it in GitHub Desktop.
Some go snippets for luasnip
local ls = require "luasnip"
local s = ls.snippet
local i = ls.insert_node
local t = ls.text_node
local f = ls.function_node
local function copyname(args)
return args[1]
end
local snips = {
go = {
s(
"ef",
{
i(1, {"val"}),
t ", err := ",
i(2, {"f"}),
t "(",
i(3),
t ")",
i(0)
}
),
s(
"pf",
{
-- Simple static text.
t("// "),
-- function, first parameter is the function, second the Placeholders
-- whose text it gets as input.
f(copyname, 1),
i(4, {" ... "}), -- paste function name
t({"", "func "}),
-- Placeholder/Insert.
i(1),
t("("),
-- Placeholder with initial text.
i(2, ""),
t(")"),
i(3, {" error "}),
-- Linebreak
t({"{", "\t"}),
-- Last Placeholder, exit Point of the snippet. EVERY 'outer' SNIPPET NEEDS Placeholder 0.
i(0),
t({"", "}"})
}
)
}
}
return snips
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment