Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 04826f3

Browse files
committedMar 23, 2019
#37: Don't print error starightaway
Avoids python stacktrace, makes error readable later
1 parent bcf6af8 commit 04826f3

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed
 

‎lua/acid/middlewares/err.lua

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
-- luacheck: globals vim
22
local err = {}
33

4+
local cache = {}
5+
46
err.middleware = function(config)
57
return function(middleware)
68
return function(data)
79
local has_err = false
810
if data.ex ~= nil then
911
has_err = true
10-
vim.api.nvim_err_writeln(data.ex)
12+
table.insert(cache, data.ex)
1113
end
1214
if data.err ~= nil then
1315
has_err = true
14-
vim.api.nvim_err_writeln(data.err)
16+
table.insert(cache, data.err)
1517
end
1618

1719
if not has_err or not config.bail_out then
@@ -21,4 +23,15 @@ err.middleware = function(config)
2123
end
2224
end
2325

26+
err.show = function(ix)
27+
ix = ix or 0
28+
local sz = #cache
29+
local pos = sz - ((sz - ix) % sz)
30+
vim.api.nvim_err_writeln(cache[pos])
31+
end
32+
33+
err.clear = function()
34+
cache = {}
35+
end
36+
2437
return err

‎lua/acid/middlewares/init.lua

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ local utils = require("acid.utils")
22

33
local nop = function(data) return data end
44

5+
local err = require("acid.middlewares.err").middleware{}(nop)
6+
7+
58
local function builder(tbl, outer, key)
69
local middleware = require("acid.middlewares." .. key)
710
return function(config)
@@ -18,4 +21,4 @@ local function builder(tbl, outer, key)
1821
end
1922
end
2023

21-
return setmetatable({}, {__index = function(_, key) return builder({}, nop, key) end})
24+
return setmetatable({}, {__index = function(_, key) return builder({}, err, key) end})

‎lua/acid/middlewares/print.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ do_print.middleware = function(config)
1111
vim.api.nvim_out_write(data.value .. "\n")
1212
end
1313
if data.ex ~= nil then
14-
vim.api.nvim_err_writeln(data.ex)
14+
vim.api.nvim_out_write(data.ex .. "\n")
1515
end
1616
if data.err ~= nil then
17-
vim.api.nvim_err_writeln(data.err)
17+
vim.api.nvim_out_write(data.err .. "\n")
1818
end
1919

2020
return middleware(data)

0 commit comments

Comments
 (0)
Please sign in to comment.