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
2023-06-13 07:04:36 +02:00
local get_datetime = function ( )
2023-06-09 13:00:41 +02:00
return os.date ( " %Y-%m-%dT%H:%M:%S%z " )
end
2023-06-13 07:04:36 +02:00
-- Function to get the current date
local get_date = function ( )
return os.date ( " %Y-%m-%d " )
end
-- Function to get the current month
2023-06-10 09:37:35 +02:00
local get_month = function ( )
return os.date ( " %B " )
end
2023-06-13 07:04:36 +02:00
-- Function to get the current year
2023-06-10 09:37:35 +02:00
local get_month_year = function ( )
return os.date ( " %B-%Y " )
end
2023-06-09 13:00:41 +02:00
-- Function to get an id based on the datetime
local get_id = function ( )
return os.date ( " %Y%m%d%H%M%S " )
end
2023-06-13 07:04:36 +02:00
-- Function to get the number of the current day
local get_day = function ( )
return os.date ( " %d " )
end
2023-06-09 13:00:41 +02:00
return {
s (
{
trig = " datetime " ,
2023-06-10 09:37:35 +02:00
name = " Datetime " ,
2023-06-13 07:04:36 +02:00
dscr = " Insert the current datetime with locale daylight saving. "
} ,
{
f ( get_datetime , { } )
}
) ,
s (
{
trig = " date " ,
name = " Date " ,
dscr = " Insert the current date. "
2023-06-09 13:00:41 +02:00
} ,
{
2023-06-16 15:44:51 +02:00
f ( get_date , { } )
2023-06-09 13:00:41 +02:00
}
) ,
s (
{
trig = " id " ,
2023-06-10 09:37:35 +02:00
Name = " ID " ,
2023-06-13 07:04:36 +02:00
dscr = " Insert an id based on the current datetime. "
2023-06-09 13:00:41 +02:00
} ,
{
f ( get_id , { } )
}
) ,
2023-06-13 07:04:36 +02:00
s (
{
trig = " today " ,
Name = " Today " ,
dscr = " Insert the number of the current day. "
} ,
{
f ( get_day , { } )
}
) ,
2023-06-09 13:00:41 +02:00
s (
{
2023-06-10 09:37:35 +02:00
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. "
2023-06-09 13:00:41 +02:00
} ,
2023-06-10 09:37:35 +02:00
fmt (
[ [
2023-06-28 07:22:51 +02:00
---
title : { 1 }
date : { 3 }
id : { 4 }
tags : [ { 2 } ]
---
2023-06-10 09:37:35 +02:00
] ] ,
{
i ( 1 , " title " ) ,
i ( 2 , " tags " ) ,
2023-06-20 09:14:17 +02:00
f ( get_datetime , { } ) ,
2023-06-10 09:37:35 +02:00
f ( get_id , { } )
}
)
) ,
s (
2023-06-09 13:00:41 +02:00
{
2023-06-10 09:37:35 +02:00
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 }
creation_date : { 2 }
author : iGor milhit
categories : [ inc ]
tags : [ notes , quotidien , { 3 } ]
---
] ] ,
{
f ( get_month_year , { } ) ,
2023-06-20 09:14:17 +02:00
f ( get_datetime , { } ) ,
2023-06-10 09:37:35 +02:00
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 \n Tab 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 }
)
2023-06-28 07:22:51 +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
)
}