refactor(iferr): use vim.notify

i have tried to use _utils.runner, but i cannt figure out how to make `< file.go` for the command
This commit is contained in:
Smirnov Oleksandr 2023-08-09 12:59:52 +03:00
parent 4e80f30cb3
commit c90e0cd124

View file

@ -1,22 +1,17 @@
local c = require("gopher.config").commands local c = require("gopher.config").commands
local u = require "gopher._utils"
local iferr = {} local iferr = {}
-- That's Lua of vimscript implementation of: github.com/koron/iferr -- That's Lua of vimscript implementation of: github.com/koron/iferr
iferr.iferr = function() function iferr.iferr()
local boff = vim.fn.wordcount().cursor_bytes local boff = vim.fn.wordcount().cursor_bytes
local cmd = (c.iferr .. " -pos " .. boff) local pos = vim.fn.getcurpos()[2]
local data = vim.fn.systemlist(cmd, vim.fn.bufnr "%")
local data = vim.fn.systemlist((c.iferr .. " -pos " .. boff), vim.fn.bufnr "%")
if vim.v.shell_error ~= 0 then if vim.v.shell_error ~= 0 then
u.deferred_notify( vim.notify("iferr failed: " .. data, vim.log.levels.ERROR)
"command " .. cmd .. " exited with code " .. vim.v.shell_error,
vim.log.levels.ERROR
)
return return
end end
local pos = vim.fn.getcurpos()[2]
vim.fn.append(pos, data) vim.fn.append(pos, data)
vim.cmd [[silent normal! j=2j]] vim.cmd [[silent normal! j=2j]]
vim.fn.setpos(".", pos) vim.fn.setpos(".", pos)