From 03535cfc7cf06291d26e5b5eb9a8122e8d709d81 Mon Sep 17 00:00:00 2001 From: nullchilly Date: Wed, 13 Jul 2022 18:49:13 +0700 Subject: [PATCH] feat(compile): Add compile commands --- lua/catppuccin/command.lua | 0 lua/catppuccin/main.lua | 17 +++++++++-------- lua/catppuccin/utils/util.lua | 10 ++++++++-- plugin/catppuccin.vim | 2 ++ 4 files changed, 19 insertions(+), 10 deletions(-) create mode 100644 lua/catppuccin/command.lua diff --git a/lua/catppuccin/command.lua b/lua/catppuccin/command.lua new file mode 100644 index 0000000..e69de29 diff --git a/lua/catppuccin/main.lua b/lua/catppuccin/main.lua index 2e2046e..bcac01a 100644 --- a/lua/catppuccin/main.lua +++ b/lua/catppuccin/main.lua @@ -20,16 +20,17 @@ local function load() if f ~= nil then io.close(f) vim.cmd("luafile " .. compiled_path) + vim.api.nvim_exec_autocmds("User", { pattern = "CatppuccinLoaded" }) + return end - else - -- colorscheme gets evaluated from mapper.lua - local theme = require("catppuccin.core.mapper").apply() - local utils = require("catppuccin.utils.util") - utils.load(theme) + end + -- 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 + if catppuccin.after_loading ~= nil then + catppuccin.after_loading() end vim.api.nvim_exec_autocmds("User", { pattern = "CatppuccinLoaded" }) diff --git a/lua/catppuccin/utils/util.lua b/lua/catppuccin/utils/util.lua index 1cbb050..52a41ee 100644 --- a/lua/catppuccin/utils/util.lua +++ b/lua/catppuccin/utils/util.lua @@ -112,10 +112,11 @@ local function inspect(t) return fmt([[{ %s }]], table.concat(list, ", ")) end -function util.compile(theme) +function util.compile() if vim.fn.has "nvim-0.7" == 0 then print "Compiling requires neovim 0.7" end + local theme = require("catppuccin.core.mapper").apply() local lines = { [[ -- This file is autogenerated by CATPPUCCIN. -- Do not make changes directly to this file. @@ -162,10 +163,15 @@ vim.g.colors_name = "catppuccin"]] } end end os.execute(string.format("mkdir %s %s", vim.loop.os_uname().sysname == 'Windows' and "" or "-p", config.compile.path)) - print(string.format("mkdir %s %s", vim.loop.os_uname().sysname == 'Windows' and "" or "-p", config.compile.path)) local file = io.open(config.compile.path .. (vim.loop.os_uname().sysname == 'Windows' and "\\" or "/") .. vim.g.catppuccin_flavour .. config.compile.suffix .. ".lua", "w") file:write(table.concat(lines, "\n")) file:close() end +function util.clean() + local config = require("catppuccin.config").options + local compiled_path = config.compile.path .. (vim.loop.os_uname().sysname == 'Windows' and "\\" or "/") .. vim.g.catppuccin_flavour .. config.compile.suffix .. ".lua" + os.remove(compiled_path) +end + return util diff --git a/plugin/catppuccin.vim b/plugin/catppuccin.vim index 141b212..7395b6b 100644 --- a/plugin/catppuccin.vim +++ b/plugin/catppuccin.vim @@ -10,5 +10,7 @@ function! s:ApplyFlavour(args) abort endfunction command! -nargs=1 -complete=custom,s:FlavourCompletion Catppuccin call s:ApplyFlavour([]) +command! CatppuccinCompile lua require("catppuccin.utils.util").compile() +command! CatppuccinClean lua require("catppuccin.utils.util").clean() let g:loaded_catppuccin = 1