From bdd142dbd604183bc8ed93b903ff967b74d9f0b9 Mon Sep 17 00:00:00 2001 From: Sidhanth Rathod Date: Sat, 17 Dec 2022 16:55:30 +0530 Subject: [PATCH] clean load_config function based on @ii14 's comment https://github.com/NvChad/NvChad/pull/1704#discussion_r1040655958 --- lua/core/utils.lua | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/lua/core/utils.lua b/lua/core/utils.lua index 87eea50..d6d9a5b 100644 --- a/lua/core/utils.lua +++ b/lua/core/utils.lua @@ -4,18 +4,13 @@ local merge_tb = vim.tbl_deep_extend M.load_config = function() local config = require "core.default_config" - -- nvim_get_runtime_file always uses forward slashes regardless of platform - local chadrc_exists = vim.api.nvim_get_runtime_file('lua/custom/chadrc.lua', false)[1] + local chadrc_path = vim.api.nvim_get_runtime_file("lua/custom/chadrc.lua", false)[1] - if chadrc_exists then - local chadrc = require "custom.chadrc" - -- merge user config if it exists and is a table; otherwise display an error - if type(chadrc) == "table" then - config.mappings = M.remove_disabled_keys(chadrc.mappings, config.mappings) - config = merge_tb("force", config, chadrc) or {} - else - error "chadrc must return a table!" - end + if chadrc_path then + local chadrc = dofile(chadrc_path) + + config.mappings = M.remove_disabled_keys(chadrc.mappings, config.mappings) + config = merge_tb("force", config, chadrc) end config.mappings.disabled = nil