From c75562cbc954136f279ced91661251543b6f2a20 Mon Sep 17 00:00:00 2001 From: LordMZTE Date: Tue, 4 Jul 2023 18:41:12 +0200 Subject: [PATCH] fix(mapper): remove unnecessary globals (#529) --- lua/catppuccin/lib/mapper.lua | 62 ++++++++++++++--------------------- vim.yml | 7 ++++ 2 files changed, 32 insertions(+), 37 deletions(-) diff --git a/lua/catppuccin/lib/mapper.lua b/lua/catppuccin/lib/mapper.lua index 4139421e..bca81f68 100644 --- a/lua/catppuccin/lib/mapper.lua +++ b/lua/catppuccin/lib/mapper.lua @@ -1,39 +1,12 @@ local M = {} -local function get_integrations() - local integrations = O["integrations"] - local final_integrations = {} - - for integration in pairs(integrations) do - local cot = false - if type(integrations[integration]) == "table" then - if integrations[integration]["enabled"] == true then cot = true end - else - if integrations[integration] == true then cot = true end - end - - if cot then - final_integrations = vim.tbl_deep_extend( - "force", - final_integrations, - require("catppuccin.groups.integrations." .. integration).get() - ) - end - end - - return final_integrations -end - function M.apply(flavour) flavour = flavour or require("catppuccin").flavour - -- Borrowing global var - _G._O = O - _G._C = C - _G._U = U - _G.O = require("catppuccin").options - _G.C = require("catppuccin.palettes").get_palette(flavour) - _G.U = require "catppuccin.utils.colors" + local _O, _C, _U = O, C, U -- Borrowing global var (setfenv doesn't work with require) + O = require("catppuccin").options + C = require("catppuccin.palettes").get_palette(flavour) + U = require "catppuccin.utils.colors" C.none = "NONE" @@ -51,9 +24,27 @@ function M.apply(flavour) local theme = {} theme.syntax = require("catppuccin.groups.syntax").get() theme.editor = require("catppuccin.groups.editor").get() - theme.integrations = get_integrations() -- plugins + local final_integrations = {} + + for integration in pairs(O.integrations) do + local cot = false + if type(O.integrations[integration]) == "table" then + if O.integrations[integration].enabled == true then cot = true end + else + if O.integrations[integration] == true then cot = true end + end + + if cot then + final_integrations = vim.tbl_deep_extend( + "force", + final_integrations, + require("catppuccin.groups.integrations." .. integration).get() + ) + end + end + theme.integrations = final_integrations -- plugins theme.terminal = require("catppuccin.groups.terminal").get() -- terminal colors - local user_highlights = require("catppuccin").options.highlight_overrides + local user_highlights = O.highlight_overrides if type(user_highlights[flavour]) == "function" then user_highlights[flavour] = user_highlights[flavour](C) end theme.custom_highlights = vim.tbl_deep_extend( "keep", @@ -61,10 +52,7 @@ function M.apply(flavour) type(user_highlights.all) == "function" and user_highlights.all(C) or user_highlights.all or {} ) - -- Returning global var - _G.O = _G._O - _G.C = _G._C - _G.U = _G._U + O, C, U = _O, _C, _U -- Returning global var return theme end diff --git a/vim.yml b/vim.yml index 26dd3732..dcb4d933 100644 --- a/vim.yml +++ b/vim.yml @@ -37,6 +37,13 @@ globals: args: - type: function + C: + property: full-write + O: + property: full-write + U: + property: full-write + C.rosewater: type: string property: read-only