mirror of
https://github.com/LunarVim/LunarVim.git
synced 2025-08-31 07:09:23 +02:00
[Feature] Encapsulate config logic (#1338)
* Define core/builtins, streamline status_color interface * Encapsulate configuration in its own module * Add fallback to lv-config.lua * Rectify settings loading order to allow overriding vim options * Move default-config into config/ module * replace uv.fs_stat with utils.is_file
This commit is contained in:
parent
f6c706ac0c
commit
00b895d9e9
9 changed files with 89 additions and 54 deletions
44
lua/config/init.lua
Normal file
44
lua/config/init.lua
Normal file
|
@ -0,0 +1,44 @@
|
|||
local M = {
|
||||
path = string.format("%s/.config/lvim/config.lua", os.getenv "HOME"),
|
||||
}
|
||||
|
||||
--- Initialize lvim default configuration
|
||||
-- Define lvim global variable
|
||||
function M:init()
|
||||
local utils = require "utils"
|
||||
|
||||
require "config.defaults"
|
||||
|
||||
local builtins = require "core.builtins"
|
||||
builtins.config(self)
|
||||
|
||||
local settings = require "config.settings"
|
||||
settings.load_options()
|
||||
|
||||
-- Fallback config.lua to lv-config.lua
|
||||
if not utils.is_file(self.path) then
|
||||
local lv_config = self.path:gsub("config.lua$", "lv-config.lua")
|
||||
print(self.path, "not found, falling back to", lv_config)
|
||||
|
||||
self.path = lv_config
|
||||
end
|
||||
end
|
||||
|
||||
--- Override the configuration with a user provided one
|
||||
-- @param config_path The path to the configuration overrides
|
||||
function M:load(config_path)
|
||||
config_path = config_path or self.path
|
||||
local ok, err = pcall(vim.cmd, "luafile " .. config_path)
|
||||
if not ok then
|
||||
print("Invalid configuration", config_path)
|
||||
print(err)
|
||||
return
|
||||
end
|
||||
|
||||
self.path = config_path
|
||||
|
||||
local settings = require "config.settings"
|
||||
settings.load_commands()
|
||||
end
|
||||
|
||||
return M
|
Loading…
Add table
Add a link
Reference in a new issue