Format stub
This commit is contained in:
parent
a8575c7260
commit
a4d5a653b1
22
lua/guid.lua
22
lua/guid.lua
@ -20,8 +20,10 @@ local function guid_generate()
|
||||
return bytes
|
||||
end
|
||||
|
||||
local function guid_format(guid, style)
|
||||
style = style or 'd'
|
||||
local function guid_print(guid, style)
|
||||
if style == '' then
|
||||
style = 'd'
|
||||
end
|
||||
|
||||
-- Format specifier definition:
|
||||
-- https://learn.microsoft.com/en-us/dotnet/api/system.guid.tostring?view=net-7.0
|
||||
@ -45,20 +47,26 @@ local function guid_format(guid, style)
|
||||
format = '{0x%.2x%.2x%.2x%.2x,0x%.2x%.2x,0x%.2x%.2x,{0x%.2x,0x%.2x,0x%.2x,0x%.2x,0x%.2x,0x%.2x,0x%.2x,0x%.2x}}'
|
||||
end
|
||||
|
||||
local formatted = string.format(format, unpack(guid))
|
||||
local guid_printed = string.format(format, unpack(guid))
|
||||
if style:upper() == style then
|
||||
formatted = formatted:upper():gsub('X', 'x')
|
||||
guid_printed = guid_printed:upper():gsub('X', 'x')
|
||||
end
|
||||
|
||||
return formatted
|
||||
return guid_printed
|
||||
end
|
||||
|
||||
local function guid_insert(style)
|
||||
local pos = get_cursor_pos()
|
||||
local guid = guid_generate()
|
||||
insert_text_at_pos(guid_format(guid, style), pos)
|
||||
local guid_printed = guid_print(guid, style)
|
||||
insert_text_at_pos(guid_printed, pos)
|
||||
end
|
||||
|
||||
local function guid_format()
|
||||
|
||||
end
|
||||
|
||||
return {
|
||||
guid_insert = guid_insert
|
||||
guid_format = guid_format,
|
||||
guid_insert = guid_insert,
|
||||
}
|
||||
|
@ -10,8 +10,14 @@ local function guid_insert(ctx)
|
||||
guid.guid_insert(ctx.args)
|
||||
end
|
||||
|
||||
local function guid_format(ctx)
|
||||
guid_reload()
|
||||
guid.guid_format(ctx.args)
|
||||
end
|
||||
|
||||
if not vim.g.guid then
|
||||
vim.api.nvim_create_user_command('GuidReload', guid_reload, {})
|
||||
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('GuidReload', guid_reload, {})
|
||||
vim.g.guid = true
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user