Skip to content

Commit ac8dcca

Browse files
committed
refactor: lua metatables + comments
1 parent d36e495 commit ac8dcca

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

lua/urlview/actions.lua

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@ function M.clipboard(raw_url)
4848
utils.log(string.format("URL %s copied to clipboard", raw_url))
4949
end
5050

51-
function M.__index(_, k)
52-
if k ~= nil then
53-
return function(raw_url)
54-
return shell_exec(k, raw_url)
51+
return setmetatable(M, {
52+
-- execute action as command if it is not one of the above module keys
53+
__index = function(_, k)
54+
if k ~= nil then
55+
return function(raw_url)
56+
return shell_exec(k, raw_url)
57+
end
5558
end
56-
end
57-
end
58-
59-
return setmetatable(M, M)
59+
end,
60+
})

lua/urlview/pickers.lua

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ function M.telescope(items, opts)
5353
:find()
5454
end
5555

56-
function M.__index(_, k)
57-
if k ~= nil then
58-
utils.log(k .. " is not a valid picker, defaulting to native vim.ui.select picker.")
59-
return M.native
60-
end
61-
end
62-
63-
return setmetatable(M, M)
56+
return setmetatable(M, {
57+
-- use default `vim.ui.select` when provided an invalid picker
58+
__index = function(_, k)
59+
if k ~= nil then
60+
utils.log(k .. " is not a valid picker, defaulting to native vim.ui.select picker.")
61+
return M.native
62+
end
63+
end,
64+
})

0 commit comments

Comments
 (0)