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
local fmt = require ( " luasnip.extras.fmt " ) . fmt
-- Function to get the datetime
-- with daylight saving time
-- according to the locale
local get_datetime = function ( )
return os.date ( " %Y-%m-%dT%H:%M:%S%z " )
end
-- Function to get the current date
local get_date = function ( )
return os.date ( " %Y-%m-%d " )
end
-- Function to get the current month
local get_month = function ( )
return os.date ( " %B " )
end
-- Function to get the current year
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 " )
end
-- Function to get the number of the current day
local get_day = function ( )
return os.date ( " %d " )
end
return {
s (
{
2023-07-03 09:36:04 +02:00
trig = " dt " ,
2023-06-09 13:00:41 +02:00
name = " Datetime " ,
dscr = " Insert the current datetime with locale daylight saving. "
} ,
{
f ( get_datetime , { } )
}
) ,
s (
{
trig = " id " ,
Name = " ID " ,
dscr = " Insert an id based on the current datetime. "
} ,
{
f ( get_id , { } )
}
) ,
s (
{
trig = " today " ,
Name = " Today " ,
dscr = " Insert the number of the current day. "
} ,
{
f ( get_day , { } )
}
) ,
2023-07-03 09:36:04 +02:00
s (
{
trig = " ie " ,
Name = " Inc entry " ,
dscr = " Insert an Inc entry for today (heading level 2). "
} ,
fmt (
[ [
## { }
] ] ,
{
f ( get_day , { } )
}
)
) ,
2023-06-09 13:00:41 +02:00
s (
{
trig = " fm " ,
name = " YAML frontmatter " ,
dscr = " Insert a YAML frontmatter for markdown files. \n \n It has a datetime with the locale daylight saving time, and an ID based on the datetime. \n Tab to jump to next text input. "
} ,
fmt (
[ [
2023-06-22 15:30:23 +02:00
---
title : { 1 }
date : { 3 }
id : { 4 }
tags : [ { 2 } ]
---
2023-06-09 13:00:41 +02:00
] ] ,
{
i ( 1 , " title " ) ,
i ( 2 , " tags " ) ,
f ( get_datetime , { } ) ,
f ( get_id , { } )
}
)
) ,
s (
{
trig = " inc " ,
name = " INC YAML frontmatter " ,
dscr = " Insert a YAML frontmatter for INC notes. \n \n It has a datetime with the locale daylight saving time, prefilled title, author, categories and tags. \n Adjust the title manually. "
} ,
fmt (
[ [
---
title : { 1 }
2023-07-03 09:36:04 +02:00
date : { 2 }
id : { 4 }
2023-06-09 13:00:41 +02:00
tags : [ notes , quotidien , { 3 } ]
---
] ] ,
{
f ( get_month_year , { } ) ,
f ( get_datetime , { } ) ,
2023-07-03 09:36:04 +02:00
f ( get_month , { } ) ,
f ( get_id , { } )
2023-06-09 13:00:41 +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 next text input. \" Reference \" is automatically repeated. "
} ,
fmt (
[ [
[ { 1 } ] [ { 2 } ]
2023-07-03 09:36:04 +02:00
[ { 2 } ] : { 3 }
2023-06-09 13:00:41 +02:00
] ] ,
{
i ( 1 , " Link text " ) ,
i ( 2 , " Reference " ) ,
2023-07-03 09:36:04 +02:00
i ( 3 , " Link target " )
2023-06-09 13:00:41 +02:00
} ,
{ repeat_duplicates = true }
)
2023-06-22 15:30:23 +02:00
) ,
s (
{
trig = " tags " ,
name = " Tags " ,
dscr = " Insert a one-line tags array, in a text file (markdown). "
} ,
fmt (
[ [
tags : [ { } ]
] ] ,
{
i ( 1 , " tags " )
}
)
2023-06-09 13:00:41 +02:00
)
}