From a478ee9829cd3dc1550efc82ae01314ca6bf0028 Mon Sep 17 00:00:00 2001 From: iGor milhit Date: Mon, 3 Jul 2023 09:36:04 +0200 Subject: [PATCH] snippets: add HTML and commit snippets - Creates a new file for custom HTML snippets. - Creates three snippets to be used when updating the clinical medicine library portal with bibliographic descriptions: - A main HTML structure with CSS styling. - An item with some bibliographic description examples. - A list item with a link to an ebook online. - Creates a snippet for commit message to save working hours. - Creates snippet for incremental note commits. - Creates snippet for AoU stats commits. - Removes redundant markdown snippets for the date. - Improves the markdown snippet for incremental note entry. - Improves the LuaSnip configuration and moves it outside the nvim-cmp configuration. - Increments the French personal dictionary. Co-Authored-by: iGor milhit --- init.lua | 4 ++ my_snippets/gitcommit.lua | 48 +++++++++++++++++ my_snippets/html.lua | 111 ++++++++++++++++++++++++++++++++++++++ my_snippets/markdown.lua | 42 ++++++++------- spell/en.utf-8.add | 2 + 5 files changed, 189 insertions(+), 18 deletions(-) create mode 100644 my_snippets/gitcommit.lua create mode 100644 my_snippets/html.lua diff --git a/init.lua b/init.lua index e78ac7a..b10acad 100644 --- a/init.lua +++ b/init.lua @@ -563,6 +563,10 @@ require("luasnip.loaders.from_lua").load({paths = "~/.config/nvim/my_snippets/"} -- https://www.ejmastnak.com/tutorials/vim-latex/luasnip/#refreshing-snippets-from-a-separate-vim-instance vim.keymap.set('n', 'L', 'lua require("luasnip.loaders.from_lua").load({paths = "~/.config/nvim/my_snippets/"})', { desc = 'Reload [L]uaSnippets' }) +-- [[ Configure nvim-cmp ]] +-- See `:help cmp` +local cmp = require 'cmp' + cmp.setup { snippet = { expand = function(args) diff --git a/my_snippets/gitcommit.lua b/my_snippets/gitcommit.lua new file mode 100644 index 0000000..d0e71d2 --- /dev/null +++ b/my_snippets/gitcommit.lua @@ -0,0 +1,48 @@ +local ls = require("luasnip") +local s = ls.snippet +local t = ls.text_node +local f = ls.function_node +local fmt = require("luasnip.extras.fmt").fmt + +-- Function to get the current date +local get_date = function() + return os.date("%Y-%m-%d") +end + +return { + s( + { + trig = "hr", + name = "Heures", + dscr = "Insert a commit message for saving the worked hours." + }, + { + t("organisation: enregistre les heures") + } + ), + s( + { + trig = "ic", + name = "Incremental note commit message", + dscr = "Insert a commit message for my incremental notes commits." + }, + fmt( + [[ + Incrémente la note du {1} + ]], + { + f(get_date, {}) + } + ) + ), + s( + { + trig = "aou", + name = "AoU stats commit message", + dscr = "Commit message for an increment of AoU validation statistics." + }, + { + t("r+e: incrémente les stats de validation de l'AoU") + } + ) +} diff --git a/my_snippets/html.lua b/my_snippets/html.lua new file mode 100644 index 0000000..072d8bb --- /dev/null +++ b/my_snippets/html.lua @@ -0,0 +1,111 @@ +-- My HTML snippets +-- Below, the duplicate of brackets, for instance in the CSS code, is for +-- escaping delimiters. + +-- Set the local variables (shortcuts) +local ls = require("luasnip") +local s = ls.snippet +local i = ls.insert_node +local fmt = require("luasnip.extras.fmt").fmt + +return { + -- A main snippet setting the outer structure, with the style tag. + -- Should be completed with the nested article item below. + s( + { + trig = "mcim", + name = "Main article structure for MC portal", + dscr = "Insert an HTML structure to add bibliographic description on the clinical medicine portal." + }, + fmt( + [[ +
+ {2} + +
+ ]], + { + i(1, "Class identifier"), + i(0) + }, + { + repeat_duplicates = true + } + ) + ), + -- Snippet that inserts an article with bibliographic metatada, to be nested + -- in the upper main structure. + s( + { + trig = "mcii", + name = "Item article structure for MC portal", + dscr = "Insert an HTML structure to add an item bibliographic description on the clinical medicine portal." + }, + fmt( + [[ + {2} + ]], + { + i(1, "Class identifier"), + i(0) + }, + { + repeat_duplicates = true + } + ) + ), + -- Snippet that insert a list item with a link to an ebook online. + s( + { + trig = "eli", + name = "List item for an ebook link", + dscr = "Insert a link for an ebook nested in a list item. Designed for the medicine portal HTML structure." + }, + fmt( + [[ +
  • + + Livre électronique en ligne + . +
  • + ]], + { + i(1, "Ebook URL"), + i(2, "Language code (2 chars)"), + i(3, "Language name") + } + ) + ) +} diff --git a/my_snippets/markdown.lua b/my_snippets/markdown.lua index 052cf26..7883817 100644 --- a/my_snippets/markdown.lua +++ b/my_snippets/markdown.lua @@ -40,7 +40,7 @@ end return { s( { - trig = "datetime", + trig = "dt", name = "Datetime", dscr = "Insert the current datetime with locale daylight saving." }, @@ -48,16 +48,6 @@ return { f(get_datetime, {}) } ), - s( - { - trig = "date", - name = "Date", - dscr = "Insert the current date." - }, - { - f(get_date, {}) - } - ), s( { trig = "id", @@ -78,6 +68,23 @@ return { 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", @@ -112,9 +119,8 @@ return { [[ --- title: {1} - creation_date: {2} - author: iGor milhit - categories: [inc] + date: {2} + id: {4} tags: [notes, quotidien, {3}] --- @@ -122,7 +128,8 @@ return { { f(get_month_year, {}), f(get_datetime, {}), - f(get_month, {}) + f(get_month, {}), + f(get_id, {}) } ) ), @@ -137,13 +144,12 @@ return { [[ [{1}][{2}] - [{2}]: {3} "{4}" + [{2}]: {3} ]], { i(1, "Link text"), i(2, "Reference"), - i(3, "Link target"), - i(4, "Title") + i(3, "Link target") }, { repeat_duplicates = true } ) diff --git a/spell/en.utf-8.add b/spell/en.utf-8.add index be24260..ed88d02 100644 --- a/spell/en.utf-8.add +++ b/spell/en.utf-8.add @@ -9,3 +9,5 @@ Réaménagement biodiversité hyperindustrialisés lacto-fermentation +d'engrain +écorcheuse