From a14a4bb11817b4994fa1a931522033c6d37eb74c Mon Sep 17 00:00:00 2001 From: Matt Leong Date: Sat, 20 Nov 2021 22:34:32 -0800 Subject: [PATCH] feat(commands): Cosmic reload now will properly update themes on the fly!! --- lua/cosmic/commands.lua | 4 ++-- lua/cosmic/core/navigation/mappings.lua | 4 ++-- lua/cosmic/utils.lua | 29 ++++++++++++++++--------- readme.md | 10 +++++++++ 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/lua/cosmic/commands.lua b/lua/cosmic/commands.lua index da29aef..a4071f5 100644 --- a/lua/cosmic/commands.lua +++ b/lua/cosmic/commands.lua @@ -1,5 +1,5 @@ vim.cmd([[ command! CosmicUpdate lua require('cosmic.utils').update() -command! CosmicReload lua require('cosmic.utils').reload_cosmic() +command! CosmicReload lua require('cosmic.utils').reload_user_config(true) +command! CosmicReloadSync lua require('cosmic.utils').reload_user_config_sync() ]]) --- command! CosmicReloadSync lua require('cosmic.utils').reload_cosmic(true) diff --git a/lua/cosmic/core/navigation/mappings.lua b/lua/cosmic/core/navigation/mappings.lua index 20f6bcc..3f0fc2f 100644 --- a/lua/cosmic/core/navigation/mappings.lua +++ b/lua/cosmic/core/navigation/mappings.lua @@ -21,8 +21,8 @@ M.init = function() map('n', 'ggs', ':Telescope git_status') -- quickfix navigation - map('n', 'cp', ':cprev') - map('n', 'cn', ':cnext') + map('n', 'cp', ':cprevzz') + map('n', 'cn', ':cnextzz') -- buffer navigation map('n', 'bp', ':bprev') diff --git a/lua/cosmic/utils.lua b/lua/cosmic/utils.lua index 48bdf86..c36c47b 100644 --- a/lua/cosmic/utils.lua +++ b/lua/cosmic/utils.lua @@ -68,30 +68,39 @@ end local function clear_cache() if 0 == vim.fn.delete(vim.fn.stdpath('config') .. '/lua/cosmic/compiled.lua') then vim.cmd(':LuaCacheClear') - vim.notify('Cache cleared', vim.log.levels.INFO, { + vim.notify('Cache cleared!', vim.log.levels.INFO, { title = 'CosmicNvim', }) end end -function M.post_reload() +function M.post_reload(msg) + unload('cosmic.utils', true) unload('cosmic.core.theme.colors', true) unload('cosmic.core.theme.highlights', true) unload('cosmic.core.statusline', true) - vim.notify('CosmicNvim reloaded!', vim.log.levels.INFO, { + msg = msg or 'User config reloaded!' + vim.notify(msg, vim.log.levels.INFO, { title = 'CosmicNvim', }) end -function M.reload_cosmic(sync) - vim.cmd([[autocmd User PackerCompileDone ++once lua require('cosmic.utils').post_reload()]]) +function M.reload_user_config_sync() + M.reload_user_config() clear_cache() - unload('cosmic.pluginsInit', true) unload('cosmic.config', true) - if sync then - vim.cmd(':PackerSync') - else - vim.cmd(':PackerCompile') + unload('cosmic.pluginsInit', true) + vim.cmd( + [[autocmd User PackerCompileDone ++once lua require('cosmic.utils').post_reload('User config reloaded! \nPlease restart CosmicNvim!')]] + ) + vim.cmd(':PackerSync') +end + +function M.reload_user_config(notify) + notify = notify or false + unload('cosmic.config', true) + if notify then + M.post_reload() end end diff --git a/readme.md b/readme.md index 3f58cca..1f11d04 100644 --- a/readme.md +++ b/readme.md @@ -102,12 +102,22 @@ CosmicNvim comes with first-class support for the following themes: By default, this will assume the Cosmic git directory is placed at `vim.fn.stdpath('config')`, i.e. `~/.config/nvim`. Otherwise, you may define the shell environment variable `COSMICNVIM_INSTALL_DIR`. +#### Clear cache and sync plugins + +``` +:CosmicReloadSync +``` + +Useful for changing themes or updating plugins on the fly! + #### Reload user config ``` :CosmicReload ``` +Useful for non-plugin related changes such as editor settings or mappings. + ## Treesitter Support Enter `:TSInstall` followed by to see your options for additional language support.