From 8a0498ee48a26f928b1dc1c02fb3d84d648a1c63 Mon Sep 17 00:00:00 2001 From: Krystian Kulgawczuk <29754364+krystian-kulgawczuk@users.noreply.github.com> Date: Wed, 31 May 2023 16:19:21 +0200 Subject: [PATCH] New global variable for vertical cursor shift on GoIfErr (#347) New variable will allow to customize exactly where cursor will end up and allow user to set this exactly how they wish. This change is backwards compatible as the default is the same as was the hardcoded value. Signed-off-by: Krystian Kulgawczuk <29754364+krystian-kulgawczuk@users.noreply.github.com> --- README.md | 1 + doc/go.txt | 1 + lua/go.lua | 1 + lua/go/iferr.lua | 3 ++- 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e4bf095..8e78528 100644 --- a/README.md +++ b/README.md @@ -844,6 +844,7 @@ require('go').setup({ on_stdout = function(err, data) _, _ = err, data end, -- callback when job started on_stderr = function(err, data) _, _ = err, data end, -- callback for stderr on_exit = function(code, signal, output) _, _, _ = code, signal, output end, -- callback for jobexit, output : string + iferr_vertical_shift = 4 -- defines where the cursor will end up vertically from the begining of if err statement }) ``` diff --git a/doc/go.txt b/doc/go.txt index 4ebd81d..c16a222 100644 --- a/doc/go.txt +++ b/doc/go.txt @@ -444,6 +444,7 @@ You can setup go.nvim with following options: test_runner = "go", -- one of {`go`, `richgo`, `dlv`, `ginkgo`} run_in_floaterm = false, -- set to true to run in float window. luasnip = false, -- set true to enable included luasnip + iferr_vertical_shift = 4 -- defines where the cursor will end up vertically from the begining of if err statement after GoIfErr command } vim:tw=78:ts=8:sts=8:sw=8:ft=help:norl:expandtab diff --git a/lua/go.lua b/lua/go.lua index 5b0eea8..9c4f713 100644 --- a/lua/go.lua +++ b/lua/go.lua @@ -128,6 +128,7 @@ _GO_NVIM_CFG = { on_stdout = function(err, data) _, _ = err, data end, -- callback when job started on_stderr = function(err, data) _, _ = err, data end, -- callback for stderr on_exit = function(code, signal, output) _, _, _ = code, signal, output end, -- callback for jobexit, output : string + iferr_vertical_shift = 4 -- defines where the cursor will end up vertically from the begining of if err statement after GoIfErr command } -- TODO: nvim_{add,del}_user_command https://github.com/neovim/neovim/pull/16752 diff --git a/lua/go/iferr.lua b/lua/go/iferr.lua index d5e6f94..819b9b7 100644 --- a/lua/go/iferr.lua +++ b/lua/go/iferr.lua @@ -26,7 +26,8 @@ local run = function() vim.cmd('silent normal! j=2j') vfn.setpos('.', pos) - vim.cmd('silent normal! 4j') + local vertical_shift = tostring(_GO_NVIM_CFG.iferr_vertical_shift) .. 'j' + vim.cmd('silent normal! ' .. vertical_shift) -- end