Skip to content

Commit

Permalink
feat(loader): warn when maplocalleader is changed after init (#1326)
Browse files Browse the repository at this point in the history
* feat(loader): warn when maplocalleader is changed after init

* docs: default maplocalleader

---------

Co-authored-by: Folke Lemaitre <folke.lemaitre@gmail.com>
  • Loading branch information
TheSast and folke authored Mar 7, 2024
1 parent c96fc24 commit 0694651
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ require("lazy").setup(plugins, opts)
```lua
-- Example using a list of specs with the default options
vim.g.mapleader = " " -- Make sure to set `mapleader` before lazy so your mappings are correct
vim.g.maplocalleader = "\\" -- Same for `maplocalleader`

require("lazy").setup({
"folke/which-key.nvim",
Expand Down Expand Up @@ -537,7 +538,7 @@ Any command can have a **bang** to make the command wait till it finished. For e
if you want to sync lazy from the cmdline, you can use:

```shell
$ nvim --headless "+Lazy! sync" +qa
nvim --headless "+Lazy! sync" +qa
```

`opts` is a table with the following key-values:
Expand Down
4 changes: 4 additions & 0 deletions lua/lazy/core/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ M.me = nil
---@type string
M.mapleader = nil

---@type string
M.maplocalleader = nil

function M.headless()
return #vim.api.nvim_list_uis() == 0
end
Expand Down Expand Up @@ -245,6 +248,7 @@ function M.setup(opts)
-- disable plugin loading since we do all of that ourselves
vim.go.loadplugins = false
M.mapleader = vim.g.mapleader
M.maplocalleader = vim.g.maplocalleader

if M.headless() then
require("lazy.view.commands").setup()
Expand Down
1 change: 1 addition & 0 deletions lua/lazy/core/loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function M.setup()
Util.track()
end
Config.mapleader = vim.g.mapleader
Config.maplocalleader = vim.g.maplocalleader

-- report any warnings & errors
Config.spec:report()
Expand Down
7 changes: 7 additions & 0 deletions lua/lazy/manage/reloader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ function M.check(start)
Config.mapleader = vim.g.mapleader
end

if Loader.init_done and Config.maplocalleader ~= vim.g.maplocalleader then
vim.schedule(function()
require("lazy.core.util").warn("You need to set `vim.g.maplocalleader` **BEFORE** loading lazy")
end)
Config.maplocalleader = vim.g.maplocalleader
end

if not (start or #changes == 0) then
vim.schedule(function()
if Config.options.change_detection.notify and not Config.headless() then
Expand Down

0 comments on commit 0694651

Please sign in to comment.