From 7d734b95164c161760cf8861bf38504d1a0a16e2 Mon Sep 17 00:00:00 2001 From: Smirnov Oleksandr Date: Wed, 6 Jul 2022 23:48:16 +0300 Subject: [PATCH] feat(iferr): add first implementation --- lua/gopher/iferr.lua | 21 +++++++++++++++++++++ lua/gopher/init.lua | 1 + plugin/gopher.vim | 1 + 3 files changed, 23 insertions(+) create mode 100644 lua/gopher/iferr.lua diff --git a/lua/gopher/iferr.lua b/lua/gopher/iferr.lua new file mode 100644 index 0000000..24d4041 --- /dev/null +++ b/lua/gopher/iferr.lua @@ -0,0 +1,21 @@ +local c = require("gopher.config").config.commands +local u = require "gopher._utils" + +---Add iferr declaration +---That's Lua of vimscript implementation of: +---github.com/koron/iferr +return function() + local boff = vim.fn.wordcount().cursor_bytes + local cmd = (c.iferr .. " -pos " .. boff) + local data = vim.fn.systemlist(cmd, vim.fn.bufnr "%") + + if vim.v.shell_error ~= 0 then + u.notify("command " .. cmd .. " exited with code " .. vim.v.shell_error, "error") + return + end + + local pos = vim.fn.getcurpos()[2] + vim.fn.append(pos, data) + vim.cmd [[silent normal! j=2j]] + vim.fn.setpos(".", pos) +end diff --git a/lua/gopher/init.lua b/lua/gopher/init.lua index 54ae79e..39f5ca9 100644 --- a/lua/gopher/init.lua +++ b/lua/gopher/init.lua @@ -9,6 +9,7 @@ gopher.mod = require "gopher.gomod" gopher.get = require "gopher.goget" gopher.impl = require "gopher.impl" gopher.generate = require "gopher.gogenerate" +gopher.iferr = require "gopher.iferr" gopher.comment = require "gopher.comment" gopher.test_add = gotests.func_test gopher.test_exported = gotests.all_exported_tests diff --git a/plugin/gopher.vim b/plugin/gopher.vim index 942cc04..089c330 100644 --- a/plugin/gopher.vim +++ b/plugin/gopher.vim @@ -8,4 +8,5 @@ command! -nargs=* GoGet :lua require"gopher".get() command! -nargs=* GoImpl :lua require"gopher".impl() command! -nargs=* GoGenerate :lua require"gopher".generate() command! GoCmt :lua require"gopher".comment() +command! GoIfErr :lua require"gopher".iferr() command! GoInstallDeps :lua require"gopher".install_deps()