guid_append

This commit is contained in:
Alex Yatskov 2024-08-04 11:38:45 -07:00
parent 637e3a4c7b
commit 35679e8317
2 changed files with 21 additions and 0 deletions

View File

@ -163,6 +163,21 @@ local function guid_insert(style)
end
end
local function guid_append(style)
local append_text_at_pos = function(text, pos)
local line = vim.fn.getline(pos.row)
local prefix = string.sub(line, 0, pos.col)
local suffix = string.sub(line, pos.col)
vim.fn.setline(pos.row, prefix .. text .. suffix)
end
local guid = Guid:generate()
local guid_printed = guid:print(style)
if guid_printed then
append_text_at_pos(guid_printed, get_cursor_pos())
end
end
local function guid_format(style)
local guid_match = Guid.find(get_cursor_pos(), true)
if guid_match then
@ -190,6 +205,7 @@ end
return {
guid_format = guid_format,
guid_insert = guid_insert,
guid_append = guid_append,
guid_object = guid_object,
setup = GuidConfig.setup,
}

View File

@ -11,6 +11,10 @@ if not vim.g.guid then
require('guid').guid_insert(ctx.args)
end
local function guid_append(ctx)
require('guid').guid_append(ctx.args)
end
local function guid_format(ctx)
require('guid').guid_format(ctx.args)
end
@ -23,6 +27,7 @@ if not vim.g.guid then
vim.api.nvim_create_user_command('GuidFormat', guid_format, {nargs = '?'})
vim.api.nvim_create_user_command('GuidInsert', guid_insert, {nargs = '?'})
vim.api.nvim_create_user_command('GuidAppend', guid_append, {nargs = '?'})
vim.api.nvim_create_user_command('GuidObject', guid_object, {})
vim.api.nvim_create_user_command('GuidReload', guid_reload, {})