From 0694651fd37c3645e1683b4f392d4e38e7d2991b Mon Sep 17 00:00:00 2001 From: TheSast <27977196+TheSast@users.noreply.github.com> Date: Thu, 7 Mar 2024 16:32:07 +0000 Subject: [PATCH] feat(loader): warn when maplocalleader is changed after init (#1326) * feat(loader): warn when maplocalleader is changed after init * docs: default maplocalleader --------- Co-authored-by: Folke Lemaitre --- README.md | 3 ++- lua/lazy/core/config.lua | 4 ++++ lua/lazy/core/loader.lua | 1 + lua/lazy/manage/reloader.lua | 7 +++++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c404f638..72319179 100644 --- a/README.md +++ b/README.md @@ -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", @@ -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: diff --git a/lua/lazy/core/config.lua b/lua/lazy/core/config.lua index e5f5f1a5..6b64c9d8 100644 --- a/lua/lazy/core/config.lua +++ b/lua/lazy/core/config.lua @@ -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 @@ -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() diff --git a/lua/lazy/core/loader.lua b/lua/lazy/core/loader.lua index 2d011dca..ac5f471c 100644 --- a/lua/lazy/core/loader.lua +++ b/lua/lazy/core/loader.lua @@ -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() diff --git a/lua/lazy/manage/reloader.lua b/lua/lazy/manage/reloader.lua index c48cc9fb..e94f0388 100644 --- a/lua/lazy/manage/reloader.lua +++ b/lua/lazy/manage/reloader.lua @@ -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