Browse Source

feat: add user-defined settings live-reloading

- The settings are automatically reloaded when the `doom_config.lua` file was changed

  - The settings can be reloaded manually by pressing `SPC - d - l`
my-config
NTBBloodbath 3 years ago
parent
commit
1634ae3377
No known key found for this signature in database GPG Key ID: 18D6730BC846AAC5
  1. 11
      lua/doom/core/functions/init.lua
  2. 14
      lua/doom/extras/autocmds/init.lua
  3. 9
      lua/doom/extras/keybindings/init.lua
  4. 1
      lua/doom/modules/config/doom-whichkey.lua

11
lua/doom/core/functions/init.lua

@ -76,6 +76,17 @@ M.load_custom_settings = function(settings_tbl, scope)
end
end
-- reload_custom_settings reloads all the user-defined configurations
-- in the 'doom_config.lua' file.
M.reload_custom_settings = function()
-- Get the user-defined settings, the 'nvim' field in our 'doom_config.lua'
local custom_settings = require("doom.core.config").load_config().nvim
-- iterate over all the custom settings fields, e.g. global_variables, mappings, etc.
for scope, _ in pairs(custom_settings) do
M.load_custom_settings(custom_settings[scope], scope)
end
end
-- Quit Neovim and change the colorscheme at doomrc if the colorscheme is not the same,
-- dump all messages to doom.log file
-- @tparam bool write If doom should save before exiting

14
lua/doom/extras/autocmds/init.lua

@ -18,6 +18,12 @@ local autocmds = {
"*/doom-*.lua,doomrc.lua,plugins.lua",
"PackerCompile profile=true",
},
-- Reload user-defined settings when 'doom_config.lua' file was modified
{
"BufWritePost",
"doom_config.lua",
"lua require('doom.core.functions').reload_user_settings()",
},
},
doom_extras = {
-- Set up vim_buffer_previewer in telescope.nvim
@ -101,10 +107,10 @@ if config.doom.preserve_edit_pos then
"BufReadPost",
"*",
[[
if line("'\"") > 1 && line("'\"") <= line("$") |
exe "normal! g'\"" |
endif
]],
if line("'\"") > 1 && line("'\"") <= line("$") |
exe "normal! g'\"" |
endif
]],
})
end

9
lua/doom/extras/keybindings/init.lua

@ -583,6 +583,15 @@ utils.map(
"show_keybindings",
"Show Doom keybindings"
)
utils.map(
"n",
"<leader>dl",
"<cmd>lua require('doom.core.functions').reload_custom_settings()<CR>",
opts,
"Doom",
"reload_user_settings",
"Reload user custom settings"
)
-- Plugins
utils.map(

1
lua/doom/modules/config/doom-whichkey.lua

@ -110,6 +110,7 @@ return function()
["r"] = { "Rollback Doom Nvim version" },
["R"] = { "Create crash report" },
["s"] = { "Change colorscheme" },
["l"] = { "Reload user custom settings" },
},
["f"] = {
name = "+file",

Loading…
Cancel
Save