local M = {} function M.map(mode, lhs, rhs, opts) local options = { noremap = true } if opts then options = vim.tbl_extend("force", options, opts) end vim.keymap.set(mode, lhs, rhs, options) end -- Print contents of `tbl`, with indentation. -- `indent` sets the initial level of indentation. function M.tprint(tbl, indent) if not indent then indent = 0 end if type(tbl) == "table" then for k, v in pairs(tbl) do local formatting = string.rep(" ", indent) .. k .. ": " if type(v) == "table" then --print(string.rep(" ", indent) .. k .. ": ") print(formatting) M.tprint(v, indent + 1) elseif type(v) == "string" then print(formatting .. v) else --print(string.rep(" ", indent) .. k .. ": " .. v) print(formatting .. tostring(v)) end end elseif type(tbl) == "string" then print(tbl) else print(tostring(tbl)) end end function M.dump(o) if type(o) == 'table' then local s = '{ ' for k, v in pairs(o) do if type(k) ~= 'number' then k = '"' .. k .. '"' end s = s .. '[' .. k .. '] = ' .. M.dump(v) .. ',' end return s .. '} ' else return tostring(o) end end function M.getLine(lines, startCol) local count = 0 local currentLine = 0 for line in lines:gmatch("[^\n]*\n?") do local currentCount = count + string.len(line) + 2 if currentCount >= startCol then local lineStartCol = startCol - count return line, currentLine, lineStartCol else currentLine = currentLine + 1 count = currentCount end end end return M