279 lines
5.8 KiB
Lua
279 lines
5.8 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_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(
|
|
{
|
|
trig = "dt",
|
|
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, {})
|
|
}
|
|
),
|
|
s(
|
|
{
|
|
trig = "ie",
|
|
Name = "Inc entry",
|
|
dscr = "Insert an Inc entry for today (heading level 2)."
|
|
},
|
|
fmt(
|
|
[[
|
|
## {}
|
|
|
|
|
|
]],
|
|
{
|
|
f(get_day, {})
|
|
}
|
|
)
|
|
),
|
|
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_datetime, {}),
|
|
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}
|
|
date: {2}
|
|
id: {4}
|
|
tags: [notes, quotidien, {3}]
|
|
---
|
|
|
|
]],
|
|
{
|
|
f(get_month_year, {}),
|
|
f(get_datetime, {}),
|
|
f(get_month, {}),
|
|
f(get_id, {})
|
|
}
|
|
)
|
|
),
|
|
s(
|
|
{
|
|
trig = "run",
|
|
name = "YAML frontmatter for a running note",
|
|
dscr = "Insert a YAML frontmatter for running notes.\n\nIt has a date for the title, a datetime with the locale daylight saving time for the date and id field, some prefilled tags. Other specific metadata for running are to be filled. This snippet should be adapted when following another plan."
|
|
},
|
|
fmt(
|
|
[[
|
|
---
|
|
title: {3}
|
|
date: {4}
|
|
id: {5}
|
|
tags: [{1}]
|
|
séance:
|
|
- type: "{2}"
|
|
données:
|
|
- privées: ""
|
|
- publiques: ""
|
|
---
|
|
|
|
]],
|
|
{
|
|
i(1, "tags"),
|
|
i(2, "workout type"),
|
|
-- i(3, "week number of the plan"),
|
|
-- i(4, "workout number of the week"),
|
|
f(get_date, {}),
|
|
f(get_datetime, {}),
|
|
f(get_id, {})
|
|
}
|
|
)
|
|
),
|
|
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}
|
|
]],
|
|
{
|
|
i(1, "Link text"),
|
|
i(2, "Reference"),
|
|
i(3, "Link target")
|
|
},
|
|
{ repeat_duplicates = true }
|
|
)
|
|
),
|
|
s(
|
|
{
|
|
trig = "tags",
|
|
name = "Tags",
|
|
dscr = "Insert a one-line tags array, in a text file (markdown)."
|
|
},
|
|
fmt(
|
|
[[
|
|
tags: [{}]
|
|
]],
|
|
{
|
|
i(1, "tags")
|
|
}
|
|
)
|
|
),
|
|
s(
|
|
{
|
|
trig = "refsen",
|
|
name = "References",
|
|
dscr = "Insert an HTML comment for references."
|
|
},
|
|
t("<!-- references -->")
|
|
),
|
|
s(
|
|
{
|
|
trig = "refsfr",
|
|
name = "Références",
|
|
dscr = "Insert an HTML comment for references, but in French."
|
|
},
|
|
t("<!-- références -->")
|
|
),
|
|
s(
|
|
{
|
|
trig="bq",
|
|
name = "[hugo] Blockquote shortcode",
|
|
dscr="Insert the shortcode for a blockquote used in my HUGO website.",
|
|
docstring = "{{< blockquote lang=\"[lang code]\" author=\"[author]\"\n title=\"[title]\"\n link=\"[link]\" >}}\n\n[Quoted text]\n{{< /blockquote >}}."
|
|
},
|
|
fmt(
|
|
[[
|
|
{{{{< blockquote lang="{1}" author="{2}"
|
|
title="{3}"
|
|
link="{4}" >}}}}
|
|
|
|
{5}
|
|
{{{{< /blockquote >}}}}
|
|
]],
|
|
{
|
|
i(1, "Lang code"),
|
|
i(2, "Author"),
|
|
i(3, "Title"),
|
|
i(4, "Link"),
|
|
i(5, "Quoted text")
|
|
}
|
|
)
|
|
),
|
|
s(
|
|
{
|
|
trig="st",
|
|
name = "[hugo] [St]ream shortcode",
|
|
dscr="Insert the shortcode for a streamed live used in my HUGO website.",
|
|
docstring = "{{< stream legend=\"[Caption]\" >}}."
|
|
},
|
|
fmt(
|
|
[[
|
|
{{{{< stream legend="{1} >}}}}"
|
|
]],
|
|
{
|
|
i(1, "Caption"),
|
|
}
|
|
)
|
|
),
|
|
s(
|
|
{
|
|
trig="pl",
|
|
name = "[hugo] [P]ublished [L]ive shortcode",
|
|
dscr="Insert the shortcode for a published live used in my HUGO website.",
|
|
docstring = "{{< published src=\"[source URL]\" legend=\"[Caption]\" >}}."
|
|
},
|
|
fmt(
|
|
[[
|
|
{{{{< published src="{1}" legend="{2}" >}}}}
|
|
]],
|
|
{
|
|
i(1, "source URL"),
|
|
i(2, "Caption"),
|
|
}
|
|
)
|
|
),
|
|
}
|