-
Previously i had a very (3000 lines long) snippets file for here is an example of a tree:
every subfile would return a luatable of snippets, eg:local ls = require("luasnip")
local s = ls.snippet -- build snippets
local fmt = require("luasnip.extras.fmt").fmta -- formatting with [[]] and delimiters=<>
return {
s({desc="desc",trig="trig"},fmt([[...]],{...})),
...
} how to group everything and load without overwritting existing snippets? im not sure if im doing it wright so far...
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 15 replies
-
I'm having the same issue. I also can't figure out how to split snippets into multiple files. I was able to write functions that return snippets in separate files and then import them in other files. Unfortunately, the add_snippets function call overwrites other add_snippets function calls. So, only one instance of add_snippets seems to be kept for each file type. But, I think I either don't fully understand LuaSnip or Lua to know how to proceed. |
Beta Was this translation helpful? Give feedback.
-
Have you tried using the lua-loade? Check the doc, the files can be structure almost exactly as you desire and it hast some nice propertiesike hot reload and jumping to snippet-definition |
Beta Was this translation helpful? Give feedback.
-
Hello! its been some time, i finnally found a solution for this. the solutions i found whent on the path of adding sinppets using The reason it wasnt working before is because we were inserting a table of tables instead of having a single table of snippets which was expected by the function. so with the following loop we can join together tables and insert then into luasnip: local snippet_tables = {
require('snippets.latex.mysnipfile'),
...
}
local snippets = {}
for _,sniptable in ipairs(snippet_tables) do
for _,snip in ipairs(sniptable) do
table.insert(snippets,snip)
end
end
ls.add_snippets('tex',snippets)
|
Beta Was this translation helpful? Give feedback.
Hello! its been some time, i finnally found a solution for this.
the solutions i found whent on the path of adding sinppets using
ls.add_snippets('tex',{...})
method.The reason it wasnt working before is because we were inserting a table of tables instead of having a single table of snippets which was expected by the function.
so with the following loop we can join together tables and insert then into luasnip:
luasnip.lua