1
0
Fork 0

more snippet work, rewrite c snippets for clarity

This commit is contained in:
Luca Bilke 2023-03-15 19:20:48 +01:00
parent ded01ee726
commit ec9ffe9e92
3 changed files with 402 additions and 359 deletions

View file

@ -3,21 +3,27 @@ if not status_ok then
return
end
local f = luasnip.function_node
luasnip.setup({
history = true,
enable_autosnippets = true,
update_events = {"TextChanged", "TextChangedI"},
snip_env = {
s = function(...)
local snip = luasnip.s(...)
table.insert(getfenv(2).ls_file_snippets, snip)
end,
ref = function(args, _)
return args[1][1]
end,
parse = function(...)
local snip = luasnip.parser.parse_snippet(...)
table.insert(getfenv(2).ls_file_snippets, snip)
end,
reference = function(node)
return f(function(args, _) return args[1][1] end, node)
end,
capture = function(index)
return f(function(_, snip, user_arg1) return snip.captures[user_arg1] end, nil, { user_args = { index } })
end
},
})

View file

@ -1,358 +1,330 @@
-- NOTE: Uncomment to fix LSP warnings
local ls = require("luasnip")
local s = ls.snippet
local ref = function(args, _)
return args[1][1]
end
local t = ls.text_node
local i = ls.insert_node
local f = ls.function_node
--
-- local sn = ls.snippet_node
-- local c = ls.choice_node
-- local d = ls.dynamic_node
-- local l = require("luasnip.extras").lambda
-- local r = require("luasnip.extras").rep
-- local p = require("luasnip.extras").partial
-- local m = require("luasnip.extras").match
-- local n = require("luasnip.extras").nonempty
-- local dl = require("luasnip.extras").dynamic_lambda
-- local fmt = require("luasnip.extras.fmt").fmt
-- local fmta = require("luasnip.extras.fmt").fmta
-- local types = require("luasnip.util.types")
-- local conds = require("luasnip.extras.expand_conditions")
-- local isn = ls.indent_snippet_node
-- local events = require("luasnip.util.events")
return {
s({ trig = "sst", name = "Standard Template" }, {
t({ "#include <stdlib.h>",
"#include <stdio.h>",
"",
"int main(int argc, char *argv[]) {",
"\t"
}),
i(0),
t({ "",
"\treturn EXIT_SUCCESS;",
"}"
}),
}),
s({ trig = "sstp", name = "Preprocessor Template" }, {
t({ "// #define NDEBUG // disables assert()",
"#include <stdlib.h>",
"#include <stddef.h>",
"#include <stdbool.h>",
"#include <assert.h>",
"#include <errno.h>",
"#include <stdio.h>",
""
}),
}),
s({ trig = "main", name = "main(int argc, char *argv[])" }, {
t({
"int main(int argc, char *argv[]) {",
"\t",
}),
i(0),
t({
"",
"\treturn EXIT_SUCCESS;",
"}"
}),
}),
s({ trig = "mainn", name = "main(void)" }, {
t({
"int main(void) {",
"\t",
}),
i(0),
t({
"", "\treturn EXIT_SUCCESS;",
"}"
}),
}),
s({ trig = "#inc", name = "#include <...>" }, {
t "#include <", i(1), t ">",
}),
s({ trig = "#Inc", name = "#include \"...\"" }, {
t "#include \"", i(1), t "\"",
}),
s({ trig = "#def", name = "#define macro" }, {
t "#define ", i(1),
}),
s({ trig = "#deff", name = "#define macro()" }, {
t "#define ", i(1), t "(", i(2), t ") (", i(3), t ")",
}),
s({ trig = "#if", name = "#if" }, {
t "#if ", i(1), t({ "", "" }),
i(0),
t({ "", "#endif /* if " }), f(ref, 1), t " */",
}),
s({ trig = "#ifdef", name = "#ifdef" }, {
t "#ifdef ", i(1), t({ "", "" }),
i(0),
t({ "", "#endif /* ifdef " }), f(ref, 1), t " */",
}),
s({ trig = "#ifndef", name = "#ifndef" }, {
t "#ifndef ", i(1), t({ "", "" }),
i(0),
t({ "", "#endif /* ifndef " }), f(ref, 1), t " */",
}),
s({ trig = "once", name = "Header Include Guard" }, {
t "#ifndef ", i(1), t({ "_H", "" }),
t "#define ", f(ref, 1), t({ "_H", "" }),
i(0),
t({ "", "#endif /* end of include guard: " }), f(ref, 1), t "_H */",
}),
s({ trig = "nocpp", name = "extern C", dscr = "Disable C++ name mangling in C headers" }, {
t({
"#ifdef __cplusplus",
"extern \"C\" {",
"#endif", ""
}),
i(0),
t({
"", "#ifdef __cplusplus",
"} /* extern \"C\" */",
"#endif",
}),
}),
s({ trig = "#err", name = "#error" }, {
t "#error \"", i(1), t "\"",
}),
s({ trig = "#warn", name = "#warning" }, {
t "#warning \"", i(1), t "\"",
}),
s({ trig = "if", name = "if" }, {
t "if (", i(1), t({ ") {", "" }),
t "\t", i(2),
t({ "", "}" }),
}),
s({ trig = "ife", name = "if else" }, {
t "if (", i(1), t({ ") {", "" }),
t "\t", i(2),
t({ "", "} else {", "\t" }),
i(3),
t({ "", "}" }),
}),
s({ trig = "elif", name = "else if" }, {
t "else if (", i(1), t({ ") {", "" }),
t "\t", i(2),
t({ "", "}" }),
}),
s({ trig = "el", name = "else" }, {
t({ "else {", "" }),
t "\t", i(1),
t({ "", "}" }),
}),
s({ trig = "t", name = "Ternary" }, {
i(1), t " ? ", i(2), t " : ", i(3),
}),
s({ trig = "switch", name = "Switch" }, {
t "switch(", i(1), t({ ")", "\t" }),
i(0),
t({ "", "\tdefault:" }), i(2),
t({ "", "}" }),
}),
s({ trig = "switchn", name = "Switch Without Default" }, {
t "switch(", i(1), t({ ")", "\t" }),
i(2),
t({ "", "}" }),
}),
s({ trig = "case", name = "Case" }, {
t "case", i(1), t({ ":", "\t" }),
i(0),
}),
s({ trig = "while", name = "While" }, {
t "while (", i(1), t({ ") {", "\t" }),
i(0),
t({ "", "}" }),
}),
s({ trig = "do", name = "Do While" }, {
t({ "do {", "\t" }),
i(0),
t({ "", "while (" }), i(1), t ")",
}),
s({ trig = "for", name = "For" }, {
t "for (", i(1), t ({") {", "\t"}),
i(0),
t({ "", "}" }),
}),
s({ trig = "fund", name = "Function Declaration" }, {
i(1), t "(", i(2), t ");",
}),
s({ trig = "fun", name = "Function Definition" }, {
i(1), t "(", i(2), t({ ") {", "\t" }),
i(0),
t({ "", "}" }),
}),
s({ trig = "st", name = "Struct" }, {
t "struct ", i(1), t({ " {", "\t" }),
i(0),
t({ "", "};" }),
}),
s({ trig = "stt", name = "Struct Type" }, {
t "typedef struct ", i(1), t({ " {", "\t" }),
i(0),
t({ "", "} " }), f(ref, 1), t ";",
}),
s({ trig = "uo", name = "Union" }, {
t "union ", i(1), t({ " {", "\t" }),
i(0),
t({ "", "};" }),
}),
s({ trig = "uot", name = "Union Type" }, {
t "typedef union ", i(1), t({ " {", "\t" }),
i(0),
t({ "", "} " }), f(ref, 1), t ";",
}),
s({ trig = "enum", name = "Enum" }, {
t "enum ", i(1), t({ " {", "\t" }),
i(0),
t({ "", "};" }),
}),
s({ trig = "enumt", name = "Enum Type" }, {
t "typedef enum ", i(1), t({ " {", "\t" }),
i(0),
t({ "", "} " }), f(ref, 1), t ";",
}),
s({ trig = "pri", name = "printf()" }, {
t "printf(\"", i(1, "%s"), t "\\n\"", i(2), t ");",
}),
s({ trig = "fpri", name = "fprintf()" }, {
t "fprintf(", i(1, "stderr"), t ", \"", i(2, "%s"), t "\\n\"", i(3), t ");",
}),
s({ trig = "spri", name = "sprintf()" }, {
t "sprintf(", i(1, "buf"), t ", \"", i(2, "%s"), t "\\n\"", i(3), t ");",
}),
s({ trig = "snpri", name = "snprintf()" }, {
t "snprintf(", i(1, "buf"), t ", ", i(2, "max"), t ", \"", i(3, "%s"), t "\\n\"", i(4), t ");",
}),
s({ trig = "sca", name = "scanf()" }, {
t "scanf(\"", i(1, "%i"), t "\"", i(2), t ");",
}),
s({ trig = "fsca", name = "fscanf()" }, {
t "fscanf(", i(1, "stdin"), t ", \"", i(2, "%i"), t "\"", i(3), t ");",
}),
s({ trig = "ssca", name = "sscanf()" }, {
t "sscanf(", i(1, "buf"), t ", \"", i(2, "%i"), t "\"", i(3), t ");",
}),
s({ trig = "priv", name = "printf()" }, {
t "printf(\"", f(ref, 2), t " = ", i(1, "%i"), t "\\n\", ", i(2), t ");",
}),
s({ trig = "warn", name = "warn()" }, {
t "warn(\"", i(1, "%s"), t "\"", i(2), t ");",
}),
s({ trig = "warnx", name = "warnx()" }, {
t "warnx(\"", i(1, "%s"), t "\"", i(2), t ");",
}),
s({ trig = "err", name = "err()" }, {
t "err(\"", i(1, "%s"), t "\"", i(2), t ");",
}),
s({ trig = "errx", name = "errx()" }, {
t "errx(\"", i(1, "%s"), t "\"", i(2), t ");",
}),
s({ trig = "asr", name = "assert()" }, {
t "assert(", i(1), t ");",
}),
s({ trig = "stasr", name = "static_assert()" }, {
t "assert(", i(1), t ", \"", i(2, "Fuck!"), t "\");",
}),
s({ trig = "Stasr", name = "static_assert() 1 Parameter" }, {
t "static_assert(", i(1), t ");",
}),
s({ trig = "mlc", name = "malloc()" }, {
i(1, "ptr"), t " = malloc(sizeof(", i(2, "int"), t "[", i(3), t "])", i(0), t ");"
}),
s({ trig = "clc", name = "calloc()" }, {
i(1, "ptr"), t " = calloc(", i(2), t ", sizeof(", i(3, "int"), t ")", i(0), t ");"
}),
s({ trig = "rlc", name = "realloc()" }, {
i(1, "ptr"), t " = realloc(", i(2), t ", sizeof(", i(3, "int"), t "[", i(4), t "])", i(0), t ");"
}),
s({ trig = "fre", name = "free()" }, {
t "free(", i(1, "ptr"), t ");"
}),
s({ trig = "mlcd", name = "Malloc Declaration" }, {
i(1, "int"), t " *", i(2, "ptr"), t " = malloc(sizeof(", f(ref, 1), t "[", i(3), t "])", i(0), t ");"
}),
s({ trig = "clcd", name = "Calloc Declaration" }, {
i(1, "int"), t " *", i(2, "ptr"), t " = calloc(", i(3), t ", sizeof(", f(ref, 1), t ")", i(0), t ");"
}),
s({ trig = "mlct", name = "Malloc Template" }, {
i(1, "int"), t " *", i(2, "ptr"), t " = malloc(sizeof(", f(ref, 1), t "[", i(3), t "])", t ");",
t({ "", " if (!" }), f(ref, 2), t ") {",
t({ "", "\tfprintf(stderr, \"" }), i(4, "Failed to malloc!"), t "\\n\"", i(5), t ");",
t({ "", "\t" }), i(6, "exit(EXIT_FAILURE);"),
t({ "", "}", "", "" }),
i(0),
t("", "", ""),
t "free(", f(ref, 2), t ");"
}),
s({ trig = "clct", name = "Calloc Template" }, {
i(1, "int"), t " *", i(2, "ptr"), t " = calloc(", i(3), t ", sizeof(", f(ref, 1), t "));",
t({ "", " if (!" }), f(ref, 2), t ") {",
t({ "", "\tfprintf(stderr, \"" }), i(4, "Failed to calloc!"), t "\\n\"", i(5), t ");",
t({ "", "\t" }), i(6, "exit(EXIT_FAILURE);"),
t({ "", "}", "", "" }),
i(0),
t("", "", ""),
t "free(", f(ref, 2), t ");"
}),
s({ trig = "/", name = "Comment" }, {
t "/*", i(1), t "*/"
}),
s({ trig = "//", name = "Multiline Comment" }, {
t({ "/*", "" }),
i(0),
t({ "", "*/" })
}),
s({ trig = "///", name = "Multiline Double-Star Comment" }, {
t({ "/**", "" }),
i(0),
t({ "", "**/" })
}),
s({ trig = "dox", name = "Doxygen Template" }, {
t "/*!", i(1),
t({ "", " * @brief " }), i(2),
t({ "", " *" }),
t({ "", " * " }), i(0),
t({ "", " */" }),
}),
s({ trig = "dfun", name = "Doxygen Function" }, {
t "/*!", i(3),
t({ "", " * @brief " }), i(4),
t({ "", " *" }),
t({ "", " * " }), i(0),
t({ "", " *" }),
t({ "", " * @return " }), i(5),
t({ "", " */" }),
i(1), t "(", i(2), t ");",
}),
s({ trig = "todo", name = "Doxygen Todo" }, {
t "/*! TODO: ", i(1),
t({ "", " *" }),
t({ "", " * @todo " }), i(0),
t({ "", " */" }),
}),
s({ trig = "dgr", name = "Doxygen Group" }, {
t "/*! @name ", i(1),
t({ "", " * @{" }),
t({ "", " */", "" }),
i(0),
t({ "", "/*! @}" }),
t({ "", " */" }),
}),
s({ trig = "alen", name = "Array Length" }, {
t "(sizeof ", i(1), t " / sizeof ", f(ref, 1), t "[0])"
}),
s({ trig = "lls", name = "Linked List" }, {
t "typedef struct ", i(1, "Node"), f(ref, 1), t({ ";", "" }),
t "struct ", f(ref, 1), t({ "{", "\t" }),
i(0),
t({ "", "\t" }), f(ref, 1), i(2, "next"), t({";", ""}),
t"};"
}),
s({ trig = "sst", name = "Standard Template" }, fmt([[
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[]) {{
{}
return EXIT_SUCCESS;
}}
]], { i(0) })),
s({ trig = "sstp", name = "Preprocessor Template" }, fmt([[
// #define NDEBUG // disables assert()
#include <stdlib.h>
#include <stddef.h>
#include <stdbool.h>
#include <assert.h>
#include <errno.h>
#include <stdio.h>
]], {})),
s({ trig = "main", name = "main(int argc, char *argv[])" }, fmt([[
int main(int argc, char *argv[]) {{
{}
return EXIT_SUCCESS;
}}
]], { i(0) })),
s({ trig = "mainn", name = "main(void)" }, fmt([[
int main(void) {{
{}
return EXIT_SUCCESS;
}}
]], { i(0) })),
s({ trig = "#inc", name = "#include <...>" }, fmt([[
#include <{}>
]], { i(1) })),
s({ trig = "#inc", name = "#include \"...\"" }, fmt([[
#include "{}"
]], { i(1) })),
s({ trig = "#def", name = "#define macro" }, fmt([[
#define {}
]], { i(0) })),
s({ trig = "#deff", name = "#define macro()" }, fmt([[
#define {}({}) ({})
]], { i(1), i(2), i(3) })),
s({ trig = "#if", name = "#if" }, fmt([[
#if {}
{}
#endif /* if {} */
]], { i(1), i(0), reference(1) })),
s({ trig = "#ifdef", name = "#ifdef" }, fmt([[
#ifdef {}
{}
#endif /* ifdef {} */
]], { i(1), i(0), reference(1) })),
s({ trig = "#ifndef", name = "#ifndef" }, fmt([[
#ifndef {}
{}
#endif /* ifndef {} */
]], { i(1), i(0), reference(1) })),
s({ trig = "once", name = "Header Include Guard" }, fmt([[
#ifndef {}_H
#define {}_H
{}
#endif /* end of include guard: {} */
]], { i(1), reference(1), i(0), reference(1) })),
s({ trig = "nocpp", name = "extern C", dscr = "Disable C++ name mangling in C headers" }, fmt([[
#ifdef __cplusplus
extern "C" {{
#endif
{}
#ifdef __cplusplus
}} /* extern "C" */
#endif
]], { i(0) })),
s({ trig = "#err", name = "#error" }, fmt([[
#error "{}"
]], { i(1) })),
s({ trig = "#warn", name = "#warning" }, fmt([[
#warning "{}"
]], { i(1) })),
s({ trig = "if", name = "if" }, fmt([[
if ({}) {{
{}
}}
]], { i(1), i(0) })),
s({ trig = "ife", name = "if else" }, fmt([[
if ({}) {{
{}
}} else {{
{}
}}
]], { i(1), i(2), i(0) })),
s({ trig = "el", name = "else" }, fmt([[
else {{
{}
}}
]], { i(0) })),
s({ trig = "elif", name = "else if" }, fmt([[
else if ({}) {{
{}
}}
]], { i(1), i(0) })),
s({ trig = "t", name = "Ternary" }, fmt([[
{} ? {} : {}
]], { i(1), i(2), i(0) })),
s({ trig = "switch", name = "Switch" }, fmt([[
switch ({}) {{
{}
default:
{}
}}
]], { i(1), i(0), i(2) })),
s({ trig = "switchn", name = "Switch Without Default" }, fmt([[
switch ({}) {{
{}
}}
]], { i(1), i(0) })),
s({ trig = "case", name = "Case" }, fmt([[
case {}:
{}
]], { i(1), i(0) })),
s({ trig = "while", name = "While" }, fmt([[
while ({}) {{
{}
}}
]], { i(1), i(0) })),
s({ trig = "do", name = "Do While" }, fmt([[
do {{
{}
}} while({});
]], { i(0), i(1) })),
s({ trig = "for", name = "For" }, fmt([[
for ({}) {{
{}
}}
]], { i(1), i(0) })),
s({ trig = "ret", name = "return" }, fmt([[
return {};
]], { i(1) })),
s({ trig = "ex", name = "exit()" }, fmt([[
exit({});
]], { i(1) })),
s({ trig = "fund", name = "Function Declaration" }, fmt([[
{}({});
]], { i(1), i(2) })),
s({ trig = "fun", name = "Function Definition" }, fmt([[
{}({}) {{
{}
}}
]], { i(1), i(2), i(0) })),
s({ trig = "td", name = "typedef" }, fmt([[
typedef {};
]], { i(1) })),
s({ trig = "tdst", name = "typedef struct" }, fmt([[
typedef struct {} {};
]], { reference(1), i(1) })),
s({ trig = "tduo", name = "typedef union" }, fmt([[
typedef union {} {};
]], { reference(1), i(1) })),
s({ trig = "tden", name = "typedef enum" }, fmt([[
typedef enum {} {};
]], { reference(1), i(1) })),
s({ trig = "st", name = "Struct" }, fmt([[
struct {} {{
{}
}};
]], { i(1), i(0) })),
s({ trig = "stt", name = "Struct Type" }, fmt([[
typedef struct {} {{
{}
}} {};
]], { i(1), i(0), reference(1) })),
s({ trig = "uo", name = "Union" }, fmt([[
union {} {{
{}
}};
]], { i(1), i(0) })),
s({ trig = "uot", name = "Union Type" }, fmt([[
typedef union {} {{
{}
}} {};
]], { i(1), i(0), reference(1) })),
s({ trig = "enum", name = "Enum" }, fmt([[
enum {} {{
{}
}};
]], { i(1), i(0) })),
s({ trig = "enumt", name = "Enum Type" }, fmt([[
typedef enum {} {{
{}
}} {};
]], { i(1), i(0), reference(1) })),
s({ trig = "pri", name = "printf()" }, fmt([[
printf("{}\n", {});
]], { i(1, "%s"), i(2) })),
s({ trig = "fpri", name = "fprintf()" }, fmt([[
fprintf({}, "{}\n", {});
]], { i(1, "stderr"), i(2, "%s"), i(3) })),
s({ trig = "spri", name = "sprintf()" }, fmt([[
sprintf({}, "{}\n", {});
]], { i(1, "buf"), i(2, "%s"), i(3) })),
s({ trig = "snpri", name = "snprintf()" }, fmt([[
snprintf({}, {}, "{}\n", {});
]], { i(1, "buf"), i(2, "max"), i(3, "%s"), i(4) })),
s({ trig = "sca", name = "scanf()" }, fmt([[
scanf("{}", {});
]], { i(1, "%i"), i(2) })),
s({ trig = "fsca", name = "fscanf()" }, fmt([[
fscanf({}, "{}", {});
]], { i(1, "stdin"), i(2, "%i"), i(3) })),
s({ trig = "ssca", name = "sscanf()" }, fmt([[
sscanf({}, "{}", {});
]], { i(1, "buf"), i(2, "%i"), i(3) })),
s({ trig = "priv", name = "Print Variable" }, fmt([[
printf("{} = {}\n", {});
]], { reference(2), i(1, "%i"), i(2) })),
s({ trig = "warn", name = "warn()" }, fmt([[
warn("{}"{});
]], { i(1, "%s"), i(2) })),
s({ trig = "warnx", name = "warnx()" }, fmt([[
warnx("{}"{});
]], { i(1, "%s"), i(2) })),
s({ trig = "err", name = "err()" }, fmt([[
err("{}"{});
]], { i(1, "%s"), i(2) })),
s({ trig = "errx", name = "errx()" }, fmt([[
errx("{}"{});
]], { i(1, "%s"), i(2) })),
s({ trig = "asr", name = "assert()" }, fmt([[
assert({});
]], { i(1) })),
s({ trig = "stasr", name = "static_assert()" }, fmt([[
static_assert({}, "{}");
]], { i(1), i(2, "Fuck!") })),
s({ trig = "Stasr", name = "static_assert() 1 Parameter" }, fmt([[
static_assert({});
]], { i(1) })),
s({ trig = "mlc", name = "malloc()" }, fmt([[
{} = malloc(sizeof({}[{}]){});
]], { i(1, "ptr"), i(2, "int"), i(3), i(4) })),
s({ trig = "clc", name = "calloc()" }, fmt([[
{} = calloc({}, sizeof({}){});
]], { i(1, "ptr"), i(2), i(3, "int"), i(4) })),
s({ trig = "rlc", name = "realloc()" }, fmt([[
{} = realloc({}, sizeof({}[{}]){});
]], { i(1, "ptr"), i(2), i(3, "int"), i(4), i(5) })),
s({ trig = "fre", name = "free()" }, fmt([[
free({});
]], { i(1, "ptr") })),
s({ trig = "mlcd", name = "Malloc Declaration" }, fmt([[
{} *{} = malloc(sizeof({}[{}]){});
]], { i(1, "int"), i(2, "ptr"), reference(1), i(3), i(4) })),
s({ trig = "clcd", name = "Calloc Declaration" }, fmt([[
{} *{} = calloc({}, sizeof({}){});
]], { i(1, "int"), i(2, "ptr"), i(3), reference(1), i(4) })),
s({ trig = "mlct", name = "Malloc Template" }, fmt([[
{} *{} = malloc(sizeof({}[{}]));
if (!{}) {{
printf(stderr, "{}\n"{});
{}
}}
{}
free({});
]], { i(1, "int"), i(2, "ptr"), reference(1), i(3), reference(2), i(4, "Failed to malloc!"), i(5),
i(6, "exit(EXIT_FAILURE);"), i(0), reference(2) })),
s({ trig = "clct", name = "Calloc Template" }, fmt([[
{} *{} = calloc({}, sizeof({}));
if (!{}) {{
printf(stderr, "{}\n"{});
{}
}}
{}
free({});
]], { i(1, "int"), i(2, "ptr"), i(3), reference(1), reference(2), i(4, "Failed to calloc!"), i(5),
i(6, "exit(EXIT_FAILURE);"), i(0), reference(2) })),
s({ trig = "/", name = "Comment" }, fmt([[
/* {} */
]], { i(1) })),
s({ trig = "//", name = "Multiline Comment" }, fmt([[
/*
* {}
*/
]], { i(1) })),
s({ trig = "///", name = "Multiline Double-Star Comment" }, fmt([[
/**
** {}
**/
]], { i(1) })),
s({ trig = "dox", name = "Doxygen Template" }, fmt([[
/*! {}
* @brief {}
*
* {}
*/
]], { i(1), i(2, "This is something undocumented."), i(3, "Nothing to say here...") })),
s({ trig = "dfun", name = "Doxygen Function" }, fmt([[
/*!
* @brief {}
*
* {}
*
* @return {}
*/
{}({});
]], { i(3, "This function is undocumented."), i(4, "Nothing to say here..."), i(5, "Nothing."), i(1), i(2) })),
s({ trig = "todo", name = "Doxygen Todo" }, fmt([[
/*! TODO: {}
*
* @todo {}
*/
]], { i(1), i(2) })),
s({ trig = "dgr", name = "Doxygen Group" }, fmt([[
/*! @name {}
* {}
* @{{
*/
{}
/*! @}}
*/
]], { i(1, "Undocumented Group"), i(2, "This group is undocumented."), i(0) })),
s({ trig = "alen", name = "Array Length" }, fmt([[
(sizeof {} / sizeof {}[0])
]], { i(1), reference(1) })),
s({ trig = "lls", name = "Linked List" }, fmt([[
struct {} {{
{}
{} *{};
}} {};
]], { i(1, "Node"), i(0), reference(1), i(2, "Next"), reference(1) })),
}

View file

@ -0,0 +1,65 @@
-- NOTE: These snippets are for taking notes quickly
local ls = require("luasnip")
local s = ls.snippet
-- local sn = ls.snippet_node
-- local isn = ls.indent_snippet_node
local t = ls.text_node
local i = ls.insert_node
local f = ls.function_node
-- local c = ls.choice_node
-- local d = ls.dynamic_node
-- local r = ls.restore_node
-- local events = require("luasnip.util.events")
-- local ai = require("luasnip.nodes.absolute_indexer")
-- local extras = require("luasnip.extras")
-- local l = extras.lambda
-- local rep = extras.rep
-- local p = extras.partial
-- local m = extras.match
-- local n = extras.nonempty
-- local dl = extras.dynamic_lambda
-- local fmt = require("luasnip.extras.fmt").fmt
-- local fmta = require("luasnip.extras.fmt").fmta
-- local conds = require("luasnip.extras.expand_conditions")
-- local postfix = require("luasnip.extras.postfix").postfix
-- local types = require("luasnip.util.types")
-- local parse = require("luasnip.util.parser").parse_snippet
-- local ms = ls.multi_snippet
local function has_value(tab, val)
for _, value in ipairs(tab) do
if value == val then
return true
end
end
return false
end
local function cond_space(args, _)
print(args[1][1]:sub(1, 1))
if (args[1][1] and has_value({ ',', '.', '?', '-', ' ' }, args[1][1]:sub(1, 1))) then
return ''
end
return ' '
end
return {
}, {
s({ trig = "^beg", regTrig = true, wordTrig = false, name = "begin{} / end{}" }, {
t "\\begin{", i(1), t({ "}", "\t" }),
i(0),
t({ "", "\\end{" }), reference(1), t "}"
}),
s({ trig = "mk", name = "Inline Math" }, {
t "$", i(1), t "$", f(cond_space, 2), i(2)
}),
s({ trig = "dm", name = "Display Math" }, {
t({ "\\[", "\t" }),
i(1),
t({ "", ".\\]" })
}),
s({ trig = "([A-Za-z])(%d)", regTrig = true, wordTrig = false, name = "Auto-Subscript" }, {
capture(1), t "_", capture(2)
})
}