diff --git a/lua/catppuccin/init.lua b/lua/catppuccin/init.lua index 32b01e7..1c439f2 100644 --- a/lua/catppuccin/init.lua +++ b/lua/catppuccin/init.lua @@ -1,13 +1,5 @@ local M = {} -function M.load() - require("catppuccin.main").main("load") -end - -function M.setup(custom_opts) - require("catppuccin.config").set_options(custom_opts) -end - local flavours = {"latte", "frappe", "macchiato", "mocha"} local command = vim.api.nvim_create_user_command @@ -37,4 +29,43 @@ command("CatppuccinClean", function() require("catppuccin.utils.util").clean() end, {}) +function M.load() + local catppuccin = require("catppuccin") + + if catppuccin.before_loading ~= nil then + catppuccin.before_loading() + end + + local loaded = nil + local config = require("catppuccin.config").options + + if config.compile.enable == true then + local compiled_path = config.compile.path + .. (vim.loop.os_uname().sysname == "Windows" and "\\" or "/") + .. vim.g.catppuccin_flavour .. config.compile.suffix .. ".lua" + local f = io.open(compiled_path, "r") + if f ~= nil then + io.close(f) + vim.cmd("luafile " .. compiled_path) + loaded = true + end + end + + if not loaded then -- colorscheme gets evaluated from mapper.lua + local theme = require("catppuccin.core.mapper").apply() + local utils = require("catppuccin.utils.util") + utils.load(theme) + + if catppuccin.after_loading ~= nil then + catppuccin.after_loading() + end + end + + vim.api.nvim_exec_autocmds("User", { pattern = "CatppuccinLoaded" }) +end + +function M.setup(custom_opts) + require("catppuccin.config").set_options(custom_opts) +end + return M diff --git a/lua/catppuccin/main.lua b/lua/catppuccin/main.lua deleted file mode 100644 index 4ae7c61..0000000 --- a/lua/catppuccin/main.lua +++ /dev/null @@ -1,48 +0,0 @@ -local M = {} - -local function load() - local catppuccin = require("catppuccin") - - if catppuccin.before_loading ~= nil then - catppuccin.before_loading() - end - - local loaded = nil - local config = require("catppuccin.config").options - - if config.compile.enable == true then - local compiled_path = config.compile.path - .. (vim.loop.os_uname().sysname == "Windows" and "\\" or "/") - .. vim.g.catppuccin_flavour .. config.compile.suffix .. ".lua" - local f = io.open(compiled_path, "r") - if f ~= nil then - io.close(f) - vim.cmd("luafile " .. compiled_path) - loaded = true - end - end - - if not loaded then -- colorscheme gets evaluated from mapper.lua - local theme = require("catppuccin.core.mapper").apply() - local utils = require("catppuccin.utils.util") - utils.load(theme) - - if catppuccin.after_loading ~= nil then - catppuccin.after_loading() - end - end - - vim.api.nvim_exec_autocmds("User", { pattern = "CatppuccinLoaded" }) -end - -function M.main(option) - option = option or "load" - - if option == "load" then - load() - else - print("catppuccin: option was not recognized") - end -end - -return M