From 14310ee6b1f40425ba854d6ddc6374960fdf81ca Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Fri, 4 Sep 2020 09:49:10 -0400 Subject: fix: Don't push past midnight. You'll make clason's stuff break :/ --- lua/telescope/utils.lua | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'lua/telescope/utils.lua') diff --git a/lua/telescope/utils.lua b/lua/telescope/utils.lua index b95f626..6154889 100644 --- a/lua/telescope/utils.lua +++ b/lua/telescope/utils.lua @@ -31,7 +31,7 @@ utils.reversed_ipairs = function(t) return reversedipairsiter, t, #t + 1 end -utils.default_table_mt = { +utils.default_table_mt = { __index = function(t, k) local obj = {} rawset(t, k, obj) @@ -114,4 +114,28 @@ utils.path_shorten = (function() end end)() +-- local x = utils.make_default_callable(function(opts) +-- return function() +-- print(opts.example, opts.another) +-- end +-- end, { example = 7, another = 5 }) + +-- x() +-- x.new { example = 3 }() +function utils.make_default_callable(f, default_opts) + return setmetatable({ + new = function(opts) + opts = vim.tbl_extend("keep", opts, default_opts) + return f(opts) + end, + }, { + __call = function() + local ok, err = pcall(f(default_opts)) + if not ok then + error(debug.traceback(err)) + end + end + }) +end + return utils -- cgit v1.2.3