From 1494a5a2fbf97500599c49fe934d841098f4e009 Mon Sep 17 00:00:00 2001 From: iGor milhit Date: Sat, 10 Jun 2023 09:37:35 +0200 Subject: [PATCH] snippets: add some markdown snippets - Adds a snippet to create a link in markdown reference syntax. - Adds a frontmatter snippet for my INC notes. - Replace the fronmatter snippet for markdown with a formatted one, easier to read. - Improves the description of my markdown snippets. - Enables the search highlighting. Co-Authored-by: iGor milhit --- init.lua | 2 +- my_snippets/all.lua | 14 ------- my_snippets/markdown.lua | 89 ++++++++++++++++++++++++++++++++++------ 3 files changed, 77 insertions(+), 28 deletions(-) delete mode 100644 my_snippets/all.lua diff --git a/init.lua b/init.lua index 7ec03aa..792decc 100644 --- a/init.lua +++ b/init.lua @@ -229,7 +229,7 @@ vim.opt.rtp:append (vim.fn.stdpath ('data') .. '/site') -- NOTE: You can change these options as you wish! -- Set highlight on search -vim.o.hlsearch = false +vim.o.hlsearch = true -- Make line numbers default vim.wo.number = true diff --git a/my_snippets/all.lua b/my_snippets/all.lua deleted file mode 100644 index 0a11b6a..0000000 --- a/my_snippets/all.lua +++ /dev/null @@ -1,14 +0,0 @@ -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/my_snippets/markdown.lua b/my_snippets/markdown.lua index b3d7972..231450b 100644 --- a/my_snippets/markdown.lua +++ b/my_snippets/markdown.lua @@ -3,6 +3,7 @@ local s = ls.snippet local t = ls.text_node local i = ls.insert_node local f = ls.function_node +local fmt = require("luasnip.extras.fmt").fmt -- Function to get the datetime -- with daylight saving time @@ -11,6 +12,14 @@ local get_date = function() return os.date("%Y-%m-%dT%H:%M:%S%z") end +local get_month = function() + return os.date("%B") +end + +local get_month_year = function() + return os.date("%B-%Y") +end + -- Function to get an id based on the datetime local get_id = function() return os.date("%Y%m%d%H%M%S") @@ -20,6 +29,7 @@ return { s( { trig = "datetime", + name = "Datetime", dscr = "Insert datetime with locale daylight saving" }, { @@ -29,6 +39,7 @@ return { s( { trig = "id", + Name = "ID", dscr = "Insert an id based on the datetime" }, { @@ -37,20 +48,72 @@ return { ), s( { - trig = "yaml", - dscr = "Insert a YAML frontmatter for markdown" + trig = "fm", + name = "YAML frontmatter", + dscr = "Insert a YAML frontmatter for markdown files.\n\nIt has a datetime with the locale daylight saving time, and an ID based on the datetime.\nTab to jump to next text input." }, + fmt( + [[ + --- + title: {1} + date: {3} + id: {4} + tags: [{2}] + --- + + ]], + { + i(1, "title"), + i(2, "tags"), + f(get_date, {}), + f(get_id, {}) + } + ) + ), + s( { - t { "---", "title: " }, - i(1, "title"), - t{ "", "date: " }, - f(get_date, {}), - t{ "", "id: " }, - f(get_id, {}), - t{ "","tags: [" }, - i(2, "tags"), - t{ "]", "---", "" }, - i(0), - } + trig = "inc", + name = "INC YAML frontmatter", + dscr = "Insert a YAML frontmatter for INC notes.\n\nIt has a datetime with the locale daylight saving time, prefilled title, author, categories and tags.\nAdjust the title manually." + }, + fmt( + [[ + --- + title: {1} + creation_date: {2} + author: iGor milhit + categories: [inc] + tags: [notes, quotidien, {3}] + --- + + ]], + { + f(get_month_year, {}), + f(get_date, {}), + f(get_month, {}) + } + ) + ), + s( + { + trig="reflink", + name = "Reference link", + dscr="Insert a link with reference syntax", + docstring = "[Link text][Reference]\n\n[Reference]: Link Target \"Title\"\n\nTab to jump to next text input. \"Reference\" is automatically repeated." + }, + fmt( + [[ + [{1}][{2}] + + [{2}]: {3} "{4}" + ]], + { + i(1, "Link text"), + i(2, "Reference"), + i(3, "Link target"), + i(4, "Title") + }, + { repeat_duplicates = true } + ) ) }