Add iferr integration (#15)

* feat(iferr): add to installer & config

* feat(iferr): add first implementation

* docs(iferr): add
This commit is contained in:
Smirnov Oleksandr 2022-07-07 14:19:07 +03:00 committed by GitHub
parent 4b83da6d7f
commit eb19ecdc05
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 2 deletions

21
lua/gopher/iferr.lua Normal file
View 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