make metatable in config init.lua
This commit is contained in:
parent
5610e9a725
commit
d15112bc7d
2 changed files with 23 additions and 7 deletions
|
|
@ -12,5 +12,7 @@ end
|
||||||
vim.opt.rtp:prepend(lazypath)
|
vim.opt.rtp:prepend(lazypath)
|
||||||
|
|
||||||
require("juancwu.config").setup({
|
require("juancwu.config").setup({
|
||||||
colorscheme = "tokyonight",
|
colorscheme = function()
|
||||||
|
require("tokyonight").load()
|
||||||
|
end,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
---@class Config
|
---@class Config: ConfigOptions
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
---@class ConfigOptions
|
---@class ConfigOptions
|
||||||
|
|
@ -34,16 +34,30 @@ function M.setup(opts)
|
||||||
|
|
||||||
-- try to load colorscheme
|
-- try to load colorscheme
|
||||||
xpcall(function()
|
xpcall(function()
|
||||||
if type(options.colorscheme) == "function" then
|
if type(M.colorscheme) == "function" then
|
||||||
options.colorscheme()
|
M.colorscheme()
|
||||||
else
|
else
|
||||||
vim.cmd.colorscheme(options.colorscheme)
|
vim.cmd.colorscheme(M.colorscheme)
|
||||||
end
|
end
|
||||||
end, function(err)
|
end, function(err)
|
||||||
local msg = "Failed to load colorscheme " .. options.colorscheme .. "\n\n" .. err
|
if type(M.colorscheme) == "string" then
|
||||||
print(msg)
|
local msg = "Failed to load colorscheme " .. M.colorscheme .. "\n\n" .. err
|
||||||
|
print(msg)
|
||||||
|
else
|
||||||
|
print("Failed to load colorscheme\n\n" .. err)
|
||||||
|
end
|
||||||
vim.cmd.colorscheme("rose-pine")
|
vim.cmd.colorscheme("rose-pine")
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
setmetatable(M, {
|
||||||
|
__index = function(_, k)
|
||||||
|
if options == nil then
|
||||||
|
return vim.deepcopy(defaultOpts)[k]
|
||||||
|
end
|
||||||
|
|
||||||
|
return options[k]
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue