Created wrapped around jump + Doc
You can now jump to next annotation field with:
require('neogen').jump_next()
Added docs for cursor utilities
This commit is contained in:
@@ -97,6 +97,10 @@ neogen.generate = function(opts)
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function neogen.jump_next()
|
||||||
|
neogen.utilities.cursor.jump()
|
||||||
|
end
|
||||||
|
|
||||||
function neogen.generate_command()
|
function neogen.generate_command()
|
||||||
vim.api.nvim_command('command! -range -bar Neogen lua require("neogen").generate()')
|
vim.api.nvim_command('command! -range -bar Neogen lua require("neogen").generate()')
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,27 +2,21 @@ neogen.utilities.cursor = {}
|
|||||||
|
|
||||||
local neogen_ns = vim.api.nvim_create_namespace("neogen")
|
local neogen_ns = vim.api.nvim_create_namespace("neogen")
|
||||||
|
|
||||||
|
--- Wrapper around set_extmark with 1-based numbering for `line` and `col`, and returns the id of the created extmark
|
||||||
|
--- @param line string
|
||||||
|
--- @param col string
|
||||||
|
--- @return number
|
||||||
neogen.utilities.cursor.create = function(line, col)
|
neogen.utilities.cursor.create = function(line, col)
|
||||||
return vim.api.nvim_buf_set_extmark(0, neogen_ns, line - 1, col - 1, {})
|
return vim.api.nvim_buf_set_extmark(0, neogen_ns, line - 1, col - 1, {})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Find next created extmark and goes to it.
|
||||||
|
--- It removes the extmark afterwards.
|
||||||
neogen.utilities.cursor.go_next_extmark = function()
|
neogen.utilities.cursor.go_next_extmark = function()
|
||||||
local extm_list = vim.api.nvim_buf_get_extmarks(0, neogen_ns, 0, -1, {})
|
local extm_list = vim.api.nvim_buf_get_extmarks(0, neogen_ns, 0, -1, {})
|
||||||
if #extm_list ~= 0 then
|
if #extm_list ~= 0 then
|
||||||
vim.api.nvim_buf_del_extmark(0, neogen_ns, extm_list[1][1])
|
vim.api.nvim_buf_del_extmark(0, neogen_ns, extm_list[1][1])
|
||||||
end
|
end
|
||||||
if #extm_list ~= 0 then
|
|
||||||
vim.api.nvim_win_set_cursor(0, { extm_list[1][2] + 1, extm_list[1][3] + 1 })
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
neogen.utilities.cursor.go_next_extmark = function()
|
|
||||||
local extm_list = vim.api.nvim_buf_get_extmarks(0, neogen_ns, 0, -1, {})
|
|
||||||
if #extm_list ~= 0 then
|
|
||||||
vim.api.nvim_buf_del_extmark(0, neogen_ns, extm_list[1][1])
|
|
||||||
P("remaning marks", #extm_list - 1)
|
|
||||||
end
|
|
||||||
if #extm_list ~= 0 then
|
if #extm_list ~= 0 then
|
||||||
vim.api.nvim_win_set_cursor(0, { extm_list[1][2] + 1, extm_list[1][3] })
|
vim.api.nvim_win_set_cursor(0, { extm_list[1][2] + 1, extm_list[1][3] })
|
||||||
return true
|
return true
|
||||||
@@ -31,12 +25,14 @@ neogen.utilities.cursor.go_next_extmark = function()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Goes to next extmark and start insert mode
|
||||||
neogen.utilities.cursor.jump = function()
|
neogen.utilities.cursor.jump = function()
|
||||||
if neogen.utilities.cursor.go_next_extmark() then
|
if neogen.utilities.cursor.go_next_extmark() then
|
||||||
vim.api.nvim_command("startinsert!")
|
vim.api.nvim_command("startinsert!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Delete all active extmarks
|
||||||
neogen.utilities.cursor.del_extmarks = function()
|
neogen.utilities.cursor.del_extmarks = function()
|
||||||
local extmarks = vim.api.nvim_buf_get_extmarks(0, neogen_ns, 0, -1, {})
|
local extmarks = vim.api.nvim_buf_get_extmarks(0, neogen_ns, 0, -1, {})
|
||||||
for _, v in pairs(extmarks) do
|
for _, v in pairs(extmarks) do
|
||||||
|
|||||||
Reference in New Issue
Block a user