Skip to content

Commit

Permalink
fix(compiler): remove require call to write compiled files (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
EdenEast authored Feb 15, 2023
1 parent 2ed26d9 commit 8e6a6df
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
13 changes: 9 additions & 4 deletions lua/catppuccin/lib/compiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function M.compile(flavour)
local theme = require("catppuccin.lib.mapper").apply(flavour)
local lines = {
[[
require("catppuccin").compiled = string.dump(function()
return string.dump(function()
if vim.g.colors_name then vim.cmd("hi clear") end
vim.o.termguicolors = true
vim.g.colors_name = "catppuccin"]],
Expand Down Expand Up @@ -52,9 +52,15 @@ vim.g.colors_name = "catppuccin"]],
if vim.fn.isdirectory(O.compile_path) == 0 then vim.fn.mkdir(O.compile_path, "p") end
local file = io.open(O.compile_path .. path_sep .. flavour .. "_compiled.lua", "wb")

if vim.g.catppuccin_debug then -- Debugging purpose
local deb = io.open((path_sep == "/" and "/tmp" or os.getenv "TMP") .. "/catppuccin_debug.lua", "wb")
deb:write(table.concat(lines, "\n"))
deb:close()
end

local f = loadstring(table.concat(lines, "\n"), "=")
if not f then
local err_path = (path_sep == "/" and "/tmp" or os.getenv "TMP") .. "/catppuccin_error.lua"
local err_path = (path_sep == "/" and "/tmp" or os.getenv "TMP") .. "/catppuccin_debug.lua"
print(string.format(
[[Catppuccin (error): Most likely some mistake made in your catppuccin config
You can open %s for debugging
Expand All @@ -71,10 +77,9 @@ Below is the error message that we captured:
dofile(err_path)
return
end
f()

if file then
file:write(require("catppuccin").compiled)
file:write(f())
file:close()
else
print(
Expand Down
5 changes: 2 additions & 3 deletions lua/catppuccin/lib/vim/compiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function M.compile(flavour)
local theme = require("catppuccin.lib.mapper").apply(flavour)
local lines = {
[[
require("catppuccin").compiled = string.dump(function()
return string.dump(function()
vim.command[[
if exists("colors_name")
hi clear
Expand Down Expand Up @@ -80,10 +80,9 @@ Below is the error message that we captured:
dofile(err_path)
return
end
f()

if file then
file:write(require("catppuccin").compiled)
file:write(f())
file:close()
else
print(
Expand Down

0 comments on commit 8e6a6df

Please sign in to comment.