[Feat] add extension as argument (#57)
parent
8e9b4489b6
commit
fefaaa12be
|
@ -23,9 +23,9 @@ function main.setup(config)
|
||||||
static.config = table_utils.merge(static.config, config == nil and {} or config)
|
static.config = table_utils.merge(static.config, config == nil and {} or config)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_config()
|
local function get_config(specify_extension)
|
||||||
local code = visual_utils.get_selected_text()
|
local code = visual_utils.get_selected_text()
|
||||||
local extension = get_extension()
|
local extension = specify_extension or get_extension()
|
||||||
|
|
||||||
if string_utils.is_str_empty(code) then
|
if string_utils.is_str_empty(code) then
|
||||||
error("Please select code which you want to take snapshot first")
|
error("Please select code which you want to take snapshot first")
|
||||||
|
@ -45,18 +45,18 @@ local function get_config()
|
||||||
}, static.config)
|
}, static.config)
|
||||||
end
|
end
|
||||||
|
|
||||||
function main.copy_into_clipboard()
|
function main.copy_into_clipboard(extension)
|
||||||
generator.copy_into_clipboard(get_config())
|
generator.copy_into_clipboard(get_config(extension))
|
||||||
vim.cmd("delmarks <>")
|
vim.cmd("delmarks <>")
|
||||||
vim.notify("Save snapshot into clipboard successfully")
|
vim.notify("Save snapshot into clipboard successfully")
|
||||||
end
|
end
|
||||||
|
|
||||||
function main.save_snapshot()
|
function main.save_snapshot(extension)
|
||||||
if string_utils.is_str_empty(static.config.save_path) then
|
if string_utils.is_str_empty(static.config.save_path) then
|
||||||
error("Cannot find save_path from config")
|
error("Cannot find save_path from config")
|
||||||
end
|
end
|
||||||
|
|
||||||
generator.save_snapshot(get_config())
|
generator.save_snapshot(get_config(extension))
|
||||||
vim.cmd("delmarks <>")
|
vim.cmd("delmarks <>")
|
||||||
vim.notify("Save snapshot in " .. static.config.save_path .. " successfully")
|
vim.notify("Save snapshot in " .. static.config.save_path .. " successfully")
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
local codesnap = require("codesnap")
|
local codesnap = require("codesnap")
|
||||||
|
|
||||||
vim.api.nvim_create_user_command("CodeSnap", function()
|
local function take_snapshot(take_snapshot_function)
|
||||||
codesnap.copy_into_clipboard()
|
return function(detail)
|
||||||
end, { nargs = "*", range = "%" })
|
local args = detail.fargs
|
||||||
|
|
||||||
vim.api.nvim_create_user_command("CodeSnapSave", function()
|
take_snapshot_function(args[1])
|
||||||
codesnap.save_snapshot()
|
end
|
||||||
end, { nargs = "*", range = "%" })
|
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 = "%" })
|
||||||
|
|
Loading…
Reference in New Issue