diff options
author | kylo252 <[email protected]> | 2022-05-21 16:48:47 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2022-05-21 16:48:47 +0200 |
commit | 23df368b00bda0ed4a01fac92f7ad80998c1d34a (patch) | |
tree | 2362ff18ac68eab313380e814238fa15c1237934 /lua/lvim/config | |
parent | a2454310b6c0b5b530521a77b9b8eb290274e040 (diff) |
refactor: load the default options once (#2592)
BREAKING CHANGE: modifying the default options for keymaps and autocmds
is now done by overwriting them, since they won't be loaded into the
global `lvim` table anymore
* refactor: use the lua-commands api
* refactor!: use the lua-autocmds api
* fix(settings): let neovim handle spellfile
* feat: add log:set_log_level()
* chore: update examples
* chore: add deprecation notice for custom_groups
Diffstat (limited to 'lua/lvim/config')
-rw-r--r-- | lua/lvim/config/init.lua | 37 | ||||
-rw-r--r-- | lua/lvim/config/settings.lua | 17 |
2 files changed, 26 insertions, 28 deletions
diff --git a/lua/lvim/config/init.lua b/lua/lvim/config/init.lua index 505029a2..1af9a971 100644 --- a/lua/lvim/config/init.lua +++ b/lua/lvim/config/init.lua @@ -5,26 +5,15 @@ local M = {} local user_config_dir = get_config_dir() local user_config_file = utils.join_paths(user_config_dir, "config.lua") -local function apply_defaults(configs, defaults) - configs = configs or {} - return vim.tbl_deep_extend("keep", configs, defaults) -end - ---Get the full path to the user configuration file ---@return string function M:get_user_config_path() return user_config_file end ---- Initialize lvim default configuration --- Define lvim global variable +--- Initialize lvim default configuration and variables function M:init() - if vim.tbl_isempty(lvim or {}) then - lvim = vim.deepcopy(require "lvim.config.defaults") - local home_dir = vim.loop.os_homedir() - lvim.vsnip_dir = utils.join_paths(home_dir, ".config", "snippets") - lvim.database = { save_location = utils.join_paths(home_dir, ".config", "lunarvim_db"), auto_execute = 1 } - end + lvim = vim.deepcopy(require "lvim.config.defaults") require("lvim.keymappings").load_defaults() @@ -32,13 +21,13 @@ function M:init() builtins.config { user_config_file = user_config_file } local settings = require "lvim.config.settings" - settings.load_options() + settings.load_defaults() local autocmds = require "lvim.core.autocmds" - lvim.autocommands = apply_defaults(lvim.autocommands, autocmds.load_augroups()) + autocmds.load_defaults() local lvim_lsp_config = require "lvim.lsp.config" - lvim.lsp = apply_defaults(lvim.lsp, vim.deepcopy(lvim_lsp_config)) + lvim.lsp = vim.deepcopy(lvim_lsp_config) ---@deprecated replaced with lvim.builtin.alpha lvim.builtin.dashboard = { @@ -51,8 +40,6 @@ function M:init() custom_section = {}, footer = {}, } - - require("lvim.lsp.manager").init_defaults() end local function handle_deprecated_settings() @@ -99,25 +86,32 @@ local function handle_deprecated_settings() if lvim.builtin.dashboard.active then deprecation_notice("lvim.builtin.dashboard", "Use `lvim.builtin.alpha` instead. See LunarVim#1906") end + + if lvim.autocommands.custom_groups then + deprecation_notice( + "lvim.autocommands.custom_groups", + "Use vim.api.nvim_create_autocmd instead or check LunarVim#2592 to learn about the new syntax" + ) + end end --- Override the configuration with a user provided one -- @param config_path The path to the configuration overrides function M:load(config_path) local autocmds = require "lvim.core.autocmds" - config_path = config_path or self.get_user_config_path() + config_path = config_path or self:get_user_config_path() local ok, err = pcall(dofile, config_path) if not ok then if utils.is_file(user_config_file) then Log:warn("Invalid configuration: " .. err) else - Log:warn(string.format("Unable to find configuration file [%s]", config_path)) + vim.notify_once(string.format("Unable to find configuration file [%s]", config_path), vim.log.levels.WARN) end end handle_deprecated_settings() - autocmds.define_augroups(lvim.autocommands) + autocmds.define_autocmds(lvim.autocommands) vim.g.mapleader = (lvim.leader == "space" and " ") or lvim.leader @@ -134,7 +128,6 @@ function M:reload() vim.schedule(function() require_clean("lvim.utils.hooks").run_pre_reload() - M:init() M:load() require("lvim.core.autocmds").configure_format_on_save() diff --git a/lua/lvim/config/settings.lua b/lua/lvim/config/settings.lua index 2f47a2dc..faa28641 100644 --- a/lua/lvim/config/settings.lua +++ b/lua/lvim/config/settings.lua @@ -1,7 +1,15 @@ local M = {} -local join_paths = require("lvim.utils").join_paths M.load_default_options = function() + local utils = require "lvim.utils" + local join_paths = utils.join_paths + + local undodir = join_paths(get_cache_dir(), "undo") + + if not utils.is_directory(undodir) then + vim.fn.mkdir(undodir, "p") + end + local default_options = { backup = false, -- creates a backup file clipboard = "unnamedplus", -- allows neovim to access the system clipboard @@ -29,7 +37,7 @@ M.load_default_options = function() timeoutlen = 250, -- time to wait for a mapped sequence to complete (in milliseconds) title = true, -- set the title of window to the value of the titlestring -- opt.titlestring = "%<%F%=%l/%L - nvim" -- what the title of the window will be set to - undodir = join_paths(get_cache_dir(), "undo"), -- set an undo directory + undodir = undodir, -- set an undo directory undofile = true, -- enable persistent undo updatetime = 300, -- faster completion writebackup = false, -- if a file is being edited by another program (or was written to file while editing with another program), it is not allowed to be edited @@ -42,9 +50,6 @@ M.load_default_options = function() numberwidth = 4, -- set number column width to 2 {default 4} signcolumn = "yes", -- always show the sign column, otherwise it would shift the text each time wrap = false, -- display lines as one long line - spell = false, - spelllang = "en", - spellfile = join_paths(get_config_dir(), "spell", "en.utf-8.add"), shadafile = join_paths(get_cache_dir(), "lvim.shada"), scrolloff = 8, -- minimal number of screen lines to keep above and below the cursor. sidescrolloff = 8, -- minimal number of screen lines to keep left and right of the cursor. @@ -68,7 +73,7 @@ M.load_headless_options = function() vim.opt.swapfile = false -- don't use a swap file end -M.load_options = function() +M.load_defaults = function() if #vim.api.nvim_list_uis() == 0 then M.load_headless_options() return |