Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler): remove require call to write compiled files #406

Merged
merged 2 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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