diff --git a/init.lua b/init.lua index e43be48..4e823c1 100644 --- a/init.lua +++ b/init.lua @@ -519,9 +519,12 @@ luasnip.config.setup { snippets = { markdown = {}, }, - luasnip.filetype_extend("pandoc", {"markdown"}) + luasnip.filetype_extend("pandoc", {"markdown"}), } +-- Load snippets from ~/.config/nvim/LuaSnip/ +require("luasnip.loaders.from_lua").load({paths = "~/.config/nvim/my_snippets/"}) + cmp.setup { snippet = { expand = function(args) diff --git a/my_snippets/all.lua b/my_snippets/all.lua new file mode 100644 index 0000000..0a11b6a --- /dev/null +++ b/my_snippets/all.lua @@ -0,0 +1,14 @@ +return { + -- A snippet that expands the trigger "hi" into the string "Hello, world!". + require("luasnip").snippet( + { trig = "hi" }, + { t("Hello, world!") } + ), + + -- To return multiple snippets, use one `return` statement per snippet file + -- and return a table of Lua snippets. + require("luasnip").snippet( + { trig = "foo" }, + { t("Another snippet.") } + ) +} diff --git a/snippets/boilerplate.html b/my_snippets/boilerplate.html similarity index 100% rename from snippets/boilerplate.html rename to my_snippets/boilerplate.html diff --git a/my_snippets/markdown.lua b/my_snippets/markdown.lua new file mode 100644 index 0000000..b3d7972 --- /dev/null +++ b/my_snippets/markdown.lua @@ -0,0 +1,56 @@ +local ls = require("luasnip") +local s = ls.snippet +local t = ls.text_node +local i = ls.insert_node +local f = ls.function_node + +-- Function to get the datetime +-- with daylight saving time +-- according to the locale +local get_date = function() + return os.date("%Y-%m-%dT%H:%M:%S%z") +end + +-- Function to get an id based on the datetime +local get_id = function() + return os.date("%Y%m%d%H%M%S") +end + +return { + s( + { + trig = "datetime", + dscr = "Insert datetime with locale daylight saving" + }, + { + f(get_date, {}) + } + ), + s( + { + trig = "id", + dscr = "Insert an id based on the datetime" + }, + { + f(get_id, {}) + } + ), + s( + { + trig = "yaml", + dscr = "Insert a YAML frontmatter for markdown" + }, + { + t { "---", "title: " }, + i(1, "title"), + t{ "", "date: " }, + f(get_date, {}), + t{ "", "id: " }, + f(get_id, {}), + t{ "","tags: [" }, + i(2, "tags"), + t{ "]", "---", "" }, + i(0), + } + ) +} diff --git a/snippets/template.md b/my_snippets/template.md similarity index 100% rename from snippets/template.md rename to my_snippets/template.md