fix(command): after_loading hook

dev
nullchilly 2 years ago
parent f8967536f9
commit 288bbd18ad

@ -8,4 +8,33 @@ function M.setup(custom_opts)
require("catppuccin.config").set_options(custom_opts) require("catppuccin.config").set_options(custom_opts)
end end
local flavours = {"latte", "frappe", "macchiato", "mocha"}
local command = vim.api.nvim_create_user_command
command("Catppuccin", function(inp)
if not vim.tbl_contains(flavours, inp.args) then
local echo = require("catppuccin.utils.echo")
echo("Invalid flavour", "info")
return
end
vim.g.catppuccin_flavour = inp.args
vim.cmd "colorscheme catppuccin"
end, {
nargs = 1,
complete = function(line)
return vim.tbl_filter(function(val)
return vim.startswith(val, line)
end, flavours)
end
})
command("CatppuccinCompile", function()
require("catppuccin.utils.util").compile()
end, {})
command("CatppuccinClean", function()
require("catppuccin.utils.util").clean()
end, {})
return M return M

@ -1,34 +1,5 @@
local M = {} local M = {}
local flavours = {"latte", "frappe", "macchiato", "mocha"}
local command = vim.api.nvim_create_user_command
command("Catppuccin", function(inp)
if not vim.tbl_contains(flavours, inp.args) then
local echo = require("catppuccin.utils.echo")
echo("Invalid flavour", "info")
return
end
vim.g.catppuccin_flavour = inp.args
vim.cmd "colorscheme catppuccin"
end, {
nargs = 1,
complete = function(line)
return vim.tbl_filter(function(val)
return vim.startswith(val, line)
end, flavours)
end
})
command("CatppuccinCompile", function()
require("catppuccin.utils.util").compile()
end, {})
command("CatppuccinClean", function()
require("catppuccin.utils.util").clean()
end, {})
local function load() local function load()
local catppuccin = require("catppuccin") local catppuccin = require("catppuccin")
@ -36,18 +7,22 @@ local function load()
catppuccin.before_loading() catppuccin.before_loading()
end end
local loaded = nil
local config = require("catppuccin.config").options local config = require("catppuccin.config").options
if config.compile.enable == true then 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 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") local f = io.open(compiled_path, "r")
if f ~= nil then if f ~= nil then
io.close(f) io.close(f)
vim.cmd("luafile " .. compiled_path) vim.cmd("luafile " .. compiled_path)
vim.api.nvim_exec_autocmds("User", { pattern = "CatppuccinLoaded" }) loaded = true
return
end end
end end
-- colorscheme gets evaluated from mapper.lua
if not loaded then -- colorscheme gets evaluated from mapper.lua
local theme = require("catppuccin.core.mapper").apply() local theme = require("catppuccin.core.mapper").apply()
local utils = require("catppuccin.utils.util") local utils = require("catppuccin.utils.util")
utils.load(theme) utils.load(theme)
@ -55,6 +30,7 @@ local function load()
if catppuccin.after_loading ~= nil then if catppuccin.after_loading ~= nil then
catppuccin.after_loading() catppuccin.after_loading()
end end
end
vim.api.nvim_exec_autocmds("User", { pattern = "CatppuccinLoaded" }) vim.api.nvim_exec_autocmds("User", { pattern = "CatppuccinLoaded" })
end end

Loading…
Cancel
Save