codesnap.nvim/plugin/codesnap.lua

37 lines
1.1 KiB
Lua
Raw Normal View History

2024-02-12 22:20:51 -08:00
local codesnap = require("codesnap")
2024-02-12 22:05:36 -08:00
-- The func param is a function that come from rust side, the function
-- may raise exception to user side, the run_generator_function is used to
-- handle these function and print it friendly
local function run_generator_function(func)
xpcall(func, function(err)
print(err)
end)
end
2024-04-02 03:18:37 -07:00
local function take_snapshot(take_snapshot_function)
return function(detail)
local args = detail.fargs
2024-02-19 06:27:17 -08:00
run_generator_function(function()
take_snapshot_function(args[1])
end)
2024-04-02 03:18:37 -07:00
end
end
vim.api.nvim_create_user_command("CodeSnap", take_snapshot(codesnap.copy_into_clipboard), { nargs = "*", range = "%" })
vim.api.nvim_create_user_command("CodeSnapSave", take_snapshot(codesnap.save_snapshot), { nargs = "*", range = "%" })
2024-04-27 04:07:41 -07:00
vim.api.nvim_create_user_command(
"CodeSnapHighlight",
take_snapshot(codesnap.highlight_mode_copy_into_clipboard),
{ nargs = "*", range = "%" }
)
vim.api.nvim_create_user_command(
"CodeSnapSaveHighlight",
take_snapshot(codesnap.highlight_mode_save_snapshot),
{ nargs = "*", range = "%" }
)