2023-06-09 13:00:41 +02:00
local ls = require ( " luasnip " )
local s = ls.snippet
local t = ls.text_node
local i = ls.insert_node
local f = ls.function_node
2023-06-10 09:37:35 +02:00
local fmt = require ( " luasnip.extras.fmt " ) . fmt
2023-06-09 13:00:41 +02:00
-- 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 " ,
2023-06-10 09:37:35 +02:00
name = " Datetime " ,
2023-06-09 13:00:41 +02:00
dscr = " Insert datetime with locale daylight saving "
} ,
{
f ( get_date , { } )
}
) ,
s (
{
trig = " id " ,
2023-06-10 09:37:35 +02:00
Name = " ID " ,
2023-06-09 13:00:41 +02:00
dscr = " Insert an id based on the datetime "
} ,
{
f ( get_id , { } )
}
) ,
s (
{
trig = " yaml " ,
2023-06-10 09:37:35 +02:00
name = " YAML frontmatter " ,
2023-06-09 13:00:41 +02:00
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 ) ,
}
2023-06-10 09:37:35 +02:00
) ,
s (
{
trig = " reflink " ,
name = " Reference link " ,
dscr = " Insert a link with reference syntax " ,
docstring = " [Link text][Reference] \n \n [Reference]: Link Target \" Title \" \n \n Tab to jump to the next field to fill in. \" 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 }
)
2023-06-09 13:00:41 +02:00
)
}