Cleanup
This commit is contained in:
parent
5ef3bbe4b7
commit
27cca89e7a
15
lua/guid.lua
15
lua/guid.lua
@ -92,22 +92,23 @@ end
|
|||||||
|
|
||||||
local function guid_format(style)
|
local function guid_format(style)
|
||||||
local pos = get_cursor_pos()
|
local pos = get_cursor_pos()
|
||||||
local patterns = {
|
local guid_patterns = {
|
||||||
'{0x[0-9a-fA-F]\\{8\\},\\s*0x[0-9a-fA-F]\\{4\\},\\s*0x[0-9a-fA-F]\\{4\\},\\s*{0x[0-9a-fA-F]\\{2\\},\\s*0x[0-9a-fA-F]\\{2\\},\\s*0x[0-9a-fA-F]\\{2\\},\\s*0x[0-9a-fA-F]\\{2\\},\\s*0x[0-9a-fA-F]\\{2\\},\\s*0x[0-9a-fA-F]\\{2\\},\\s*0x[0-9a-fA-F]\\{2\\},\\s*0x[0-9a-fA-F]\\{2\\}}}',
|
'{0x[0-9a-fA-F]\\{8\\},\\s*0x[0-9a-fA-F]\\{4\\},\\s*0x[0-9a-fA-F]\\{4\\},\\s*{0x[0-9a-fA-F]\\{2\\},\\s*0x[0-9a-fA-F]\\{2\\},\\s*0x[0-9a-fA-F]\\{2\\},\\s*0x[0-9a-fA-F]\\{2\\},\\s*0x[0-9a-fA-F]\\{2\\},\\s*0x[0-9a-fA-F]\\{2\\},\\s*0x[0-9a-fA-F]\\{2\\},\\s*0x[0-9a-fA-F]\\{2\\}}}', -- x
|
||||||
'([0-9a-fA-F]\\{8\\}-[0-9a-fA-F]\\{4\\}-[0-9a-fA-F]\\{4\\}-[0-9a-fA-F]\\{4\\}-[0-9a-fA-F]\\{12\\})', -- p
|
'([0-9a-fA-F]\\{8\\}-[0-9a-fA-F]\\{4\\}-[0-9a-fA-F]\\{4\\}-[0-9a-fA-F]\\{4\\}-[0-9a-fA-F]\\{12\\})', -- p
|
||||||
'{[0-9a-fA-F]\\{8\\}-[0-9a-fA-F]\\{4\\}-[0-9a-fA-F]\\{4\\}-[0-9a-fA-F]\\{4\\}-[0-9a-fA-F]\\{12\\}}', -- b
|
'{[0-9a-fA-F]\\{8\\}-[0-9a-fA-F]\\{4\\}-[0-9a-fA-F]\\{4\\}-[0-9a-fA-F]\\{4\\}-[0-9a-fA-F]\\{12\\}}', -- b
|
||||||
'[0-9a-fA-F]\\{8\\}-[0-9a-fA-F]\\{4\\}-[0-9a-fA-F]\\{4\\}-[0-9a-fA-F]\\{4\\}-[0-9a-fA-F]\\{12\\}', -- d
|
'[0-9a-fA-F]\\{8\\}-[0-9a-fA-F]\\{4\\}-[0-9a-fA-F]\\{4\\}-[0-9a-fA-F]\\{4\\}-[0-9a-fA-F]\\{12\\}', -- d
|
||||||
'[0-9a-fA-F]\\{32\\}', -- n
|
'[0-9a-fA-F]\\{32\\}', -- n
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, pattern in ipairs(patterns) do
|
for _, guid_pattern in ipairs(guid_patterns) do
|
||||||
local match_pos = find_pattern_at_pos(pattern, pos)
|
local match_pos = find_pattern_at_pos(guid_pattern, pos)
|
||||||
if match_pos then
|
if match_pos then
|
||||||
local guid = guid_parse(match_pos.text)
|
local guid = guid_parse(match_pos.text)
|
||||||
|
local guid_printed = guid_print(guid, style)
|
||||||
local line = vim.fn.getline(pos.row)
|
local line = vim.fn.getline(pos.row)
|
||||||
local line_prefix = line:sub(1, match_pos.col - 1) ---@diagnostic disable-line: undefined-field
|
local line_prefix = line:sub(1, match_pos.col - 1) ---@diagnostic disable-line: undefined-field
|
||||||
local line_suffix = line:sub(match_pos.col + #match_pos.text) ---@diagnostic disable-line: undefined-field
|
local line_suffix = line:sub(match_pos.col + #match_pos.text) ---@diagnostic disable-line: undefined-field
|
||||||
vim.fn.setline(match_pos.row, line_prefix .. guid_print(guid, style) .. line_suffix)
|
vim.fn.setline(match_pos.row, line_prefix .. guid_printed .. line_suffix)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,23 +1,21 @@
|
|||||||
local guid = require('guid')
|
local guid = require('guid')
|
||||||
|
|
||||||
local function guid_reload()
|
local function reload()
|
||||||
package.loaded.guid = nil
|
package.loaded.guid = nil
|
||||||
guid = require('guid')
|
guid = require('guid')
|
||||||
end
|
end
|
||||||
|
|
||||||
local function guid_insert(ctx)
|
local function insert(ctx)
|
||||||
guid_reload()
|
|
||||||
guid.guid_insert(ctx.args)
|
guid.guid_insert(ctx.args)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function guid_format(ctx)
|
local function format(ctx)
|
||||||
guid_reload()
|
|
||||||
guid.guid_format(ctx.args)
|
guid.guid_format(ctx.args)
|
||||||
end
|
end
|
||||||
|
|
||||||
if not vim.g.guid then
|
if not vim.g.guid then
|
||||||
vim.api.nvim_create_user_command('GuidFormat', guid_format, {nargs = '?'})
|
vim.api.nvim_create_user_command('GuidFormat', format, {nargs = '?'})
|
||||||
vim.api.nvim_create_user_command('GuidInsert', guid_insert, {nargs = '?'})
|
vim.api.nvim_create_user_command('GuidInsert', insert, {nargs = '?'})
|
||||||
vim.api.nvim_create_user_command('GuidReload', guid_reload, {})
|
vim.api.nvim_create_user_command('GuidReload', reload, {})
|
||||||
vim.g.guid = true
|
vim.g.guid = true
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user