From c9ba1dcc5d4d62613302af31429a34849af8af31 Mon Sep 17 00:00:00 2001 From: Daniel Mathiot Date: Fri, 27 Aug 2021 22:10:14 +0200 Subject: [PATCH] Created wrapped around jump + Doc You can now jump to next annotation field with: require('neogen').jump_next() Added docs for cursor utilities --- lua/neogen.lua | 4 ++++ lua/neogen/utilities/cursor.lua | 20 ++++++++------------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lua/neogen.lua b/lua/neogen.lua index f6b414f..1698d0d 100644 --- a/lua/neogen.lua +++ b/lua/neogen.lua @@ -97,6 +97,10 @@ neogen.generate = function(opts) end) end +function neogen.jump_next() + neogen.utilities.cursor.jump() +end + function neogen.generate_command() vim.api.nvim_command('command! -range -bar Neogen lua require("neogen").generate()') end diff --git a/lua/neogen/utilities/cursor.lua b/lua/neogen/utilities/cursor.lua index bf1908b..943512a 100644 --- a/lua/neogen/utilities/cursor.lua +++ b/lua/neogen/utilities/cursor.lua @@ -2,27 +2,21 @@ neogen.utilities.cursor = {} 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) return vim.api.nvim_buf_set_extmark(0, neogen_ns, line - 1, col - 1, {}) end +--- Find next created extmark and goes to it. +--- It removes the extmark afterwards. 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]) 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 vim.api.nvim_win_set_cursor(0, { extm_list[1][2] + 1, extm_list[1][3] }) return true @@ -31,12 +25,14 @@ neogen.utilities.cursor.go_next_extmark = function() end end +--- Goes to next extmark and start insert mode neogen.utilities.cursor.jump = function() if neogen.utilities.cursor.go_next_extmark() then vim.api.nvim_command("startinsert!") end end +--- Delete all active extmarks neogen.utilities.cursor.del_extmarks = function() local extmarks = vim.api.nvim_buf_get_extmarks(0, neogen_ns, 0, -1, {}) for _, v in pairs(extmarks) do