feat(commands): Cosmic reload now will properly update themes on the fly!!

This commit is contained in:
Matt Leong 2021-11-20 22:34:32 -08:00
parent bbdf42e745
commit a14a4bb118
4 changed files with 33 additions and 14 deletions

View file

@ -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)

View file

@ -21,8 +21,8 @@ M.init = function()
map('n', '<leader>ggs', ':Telescope git_status<cr>')
-- quickfix navigation
map('n', '<leader>cp', ':cprev<cr>')
map('n', '<leader>cn', ':cnext<cr>')
map('n', '<leader>cp', ':cprev<cr>zz')
map('n', '<leader>cn', ':cnext<cr>zz')
-- buffer navigation
map('n', '<leader>bp', ':bprev<cr>')

View file

@ -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

View file

@ -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 <TAB> to see your options for additional language support.