Skip to content

Commit

Permalink
Add inspect_object function
Browse files Browse the repository at this point in the history
  • Loading branch information
Akmadan23 committed Nov 4, 2023
1 parent fa91ea0 commit 2a6a2a9
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions config/nvim/lua/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ local fmt = string.format
local exp = vim.fn.expand
local is_exe = vim.fn.executable

local echo = function(obj, opts)
vim.api.nvim_echo({{ vim.inspect(obj) }}, true, opts or {})
end

local is_file = function(f)
return vim.fn.filereadable(f) == 1
end
Expand Down Expand Up @@ -475,4 +479,28 @@ M.test = function()
end
end

--- A convenient way to inspect lua objects on the fly
M.inspect_object = function()
local opts = {
prompt = "Inspect: ",
completion = "lua"
}

vim.ui.input(opts, function(input)
if input == nil then
return
end

local f = loadstring("return " .. input)
vim.api.nvim_out_write("\n")

if f then
-- vim.print(f()) -- for some reason it does not work
echo(f())
else
notify("Error parsing lua: Syntax error.")
end
end)
end

return M

0 comments on commit 2a6a2a9

Please sign in to comment.