diff --git a/init.lua b/init.lua index a05c71d..1aa06e6 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/LuaSnip/"})', { 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..34f36c8 --- /dev/null +++ b/my_snippets/html.lua @@ -0,0 +1,109 @@ +-- 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") + } + ) + ) +}