summaryrefslogtreecommitdiff
path: root/lua/lvim/utils.lua
diff options
context:
space:
mode:
authoropalmay <[email protected]>2023-01-28 22:43:44 +0200
committeropalmay <[email protected]>2023-01-28 22:48:23 +0200
commit845522742dbfcdfd6bd83437fc5b5caf6798db60 (patch)
tree32cfc3df094cea9d983b5fa0cb31f117cffd9f89 /lua/lvim/utils.lua
parentc18cd3f0a89443d4265f6df8ce12fb89d627f09e (diff)
feat(luasnip): setup tables snip
Diffstat (limited to 'lua/lvim/utils.lua')
-rw-r--r--lua/lvim/utils.lua41
1 files changed, 41 insertions, 0 deletions
diff --git a/lua/lvim/utils.lua b/lua/lvim/utils.lua
index 5e49906a..1a4ddb1a 100644
--- a/lua/lvim/utils.lua
+++ b/lua/lvim/utils.lua
@@ -1,6 +1,47 @@
local M = {}
local uv = vim.loop
+function M.r_inspect_settings(structure, base_structure_str, limit, separator)
+ limit = limit or 100 -- default item limit
+ separator = separator or "." -- indent string
+ local output = ""
+ if limit < 1 then
+ return "ERROR: Item limit reached."
+ end
+ if structure == nil then
+ output = output .. "-- O" .. separator:sub(2) .. " = nil\n"
+ return output
+ end
+ local ts = type(structure)
+
+ if ts == "table" then
+ for k, v in pairs(structure) do
+ -- replace non alpha keys with ["key"]
+ if tostring(k):match "[^%a_]" then
+ k = '["' .. tostring(k) .. '"]'
+ end
+ output = output .. M.r_inspect_settings(v, base_structure_str, limit, separator .. "." .. tostring(k))
+ if limit < 0 then
+ break
+ end
+ end
+ return output
+ end
+
+ if ts == "string" then
+ -- escape sequences
+ structure = string.format("%q", structure)
+ end
+ separator = separator:gsub("%.%[", "%[")
+ if type(structure) == "function" then
+ -- don't print functions
+ output = output .. "-- " .. base_structure_str .. separator:sub(2) .. " = function ()\n"
+ else
+ output = output .. base_structure_str .. separator:sub(2) .. " = " .. tostring(structure) .. "\n"
+ end
+ return output
+end
+
-- recursive Print (structure, limit, separator)
local function r_inspect_settings(structure, limit, separator)
limit = limit or 100 -- default item limit