120 lines
2.4 KiB
Lua
120 lines
2.4 KiB
Lua
|
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_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")
|
||
|
end
|
||
|
|
||
|
return {
|
||
|
s(
|
||
|
{
|
||
|
trig = "datetime",
|
||
|
name = "Datetime",
|
||
|
dscr = "Insert datetime with locale daylight saving"
|
||
|
},
|
||
|
{
|
||
|
f(get_date, {})
|
||
|
}
|
||
|
),
|
||
|
s(
|
||
|
{
|
||
|
trig = "id",
|
||
|
Name = "ID",
|
||
|
dscr = "Insert an id based on the datetime"
|
||
|
},
|
||
|
{
|
||
|
f(get_id, {})
|
||
|
}
|
||
|
),
|
||
|
s(
|
||
|
{
|
||
|
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(
|
||
|
{
|
||
|
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 }
|
||
|
)
|
||
|
)
|
||
|
}
|