From 7af5f47f7af9b571d6276d957fe81c9881c033e0 Mon Sep 17 00:00:00 2001 From: iGor milhit Date: Wed, 2 Aug 2023 16:26:13 +0200 Subject: [PATCH] snippets: add HTML snippets for library portal - Creates a new file for custom HTML snippets. - Adds 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. - Improves the LuaSnip configuration and moves it outside the nvim-cmp configuration. Co-Authored-by: iGor milhit --- init.lua | 12 +++-- my_snippets/html.lua | 111 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+), 3 deletions(-) create mode 100644 my_snippets/html.lua diff --git a/init.lua b/init.lua index a05c71d..cd55754 100644 --- a/init.lua +++ b/init.lua @@ -547,9 +547,7 @@ mason_lspconfig.setup_handlers { end, } --- [[ Configure nvim-cmp ]] --- See `:help cmp` -local cmp = require 'cmp' +-- [[ Configure LuaSnip ]] local luasnip = require 'luasnip' require('luasnip.loaders.from_vscode').lazy_load() luasnip.config.setup { @@ -564,6 +562,14 @@ luasnip.config.setup { -- Load snippets from ~/.config/nvim/LuaSnip/ require("luasnip.loaders.from_lua").load({paths = "~/.config/nvim/my_snippets/"}) +-- Keymap to reload 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/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") + } + ) + ) +}