feat(iferr): add first implementation
This commit is contained in:
parent
ebfbe12461
commit
7d734b9516
3 changed files with 23 additions and 0 deletions
21
lua/gopher/iferr.lua
Normal file
21
lua/gopher/iferr.lua
Normal file
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -8,4 +8,5 @@ command! -nargs=* GoGet :lua require"gopher".get(<f-args>)
|
|||
command! -nargs=* GoImpl :lua require"gopher".impl(<f-args>)
|
||||
command! -nargs=* GoGenerate :lua require"gopher".generate(<f-args>)
|
||||
command! GoCmt :lua require"gopher".comment()
|
||||
command! GoIfErr :lua require"gopher".iferr()
|
||||
command! GoInstallDeps :lua require"gopher".install_deps()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue