diff --git a/CHANGELOG.md b/CHANGELOG.md index 6031b84b..23c18126 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,10 +20,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Issues Fix -- Fixed few regex-based/legacy highlight corrections (fixed #285) -- Closed #251 -- Fixed darkened sidebars when disabling `options.sidebars.disabled` -- Fixes #311 +- Fixed few regex-based/legacy highlight corrections (fixed #285) +- Closed #251 +- Fixed bug where the current theme gets compiled multiple times instead of compiling all themes #290 +- Fixed darkened sidebars when disabling `options.sidebars.disabled` +- Fixes #311 ## [v1.0.1] - 23 July 2023 diff --git a/lua/github-theme/config.lua b/lua/github-theme/config.lua index e6853678..1c8e9b8d 100644 --- a/lua/github-theme/config.lua +++ b/lua/github-theme/config.lua @@ -99,10 +99,10 @@ function M.reset() end function M.get_compiled_info(opts) + opts = opts or {} local output_path = opts.output_path or M.options.compile_path local file_suffix = opts.file_suffix or M.options.compile_file_suffix - local style = opts.name or M.theme - return output_path, util.join_paths(output_path, style .. file_suffix) + return output_path, util.join_paths(output_path, (opts.theme or M.theme) .. file_suffix) end function M.hash() diff --git a/lua/github-theme/init.lua b/lua/github-theme/init.lua index a2940b83..dc769bd9 100644 --- a/lua/github-theme/init.lua +++ b/lua/github-theme/init.lua @@ -24,14 +24,20 @@ function M.reset() require('github-theme.override').reset() end +---Compiles all themes/styles with their current settings. +---@return nil function M.compile() require('github-theme.lib.log').clear() - local compiler = require('github-theme.lib.compiler') local themes = require('github-theme.palette').themes - for _, style in ipairs(themes) do - compiler.compile({ style = style }) + local current_theme = config.theme + for _, theme in ipairs(themes) do + -- Compile current theme last (see discussion in #290) + if theme ~= current_theme then + compiler.compile({ theme = theme }) + end end + compiler.compile({ theme = current_theme }) end -- Avoid g:colors_name reloading diff --git a/lua/github-theme/lib/compiler.lua b/lua/github-theme/lib/compiler.lua index aa2a8af1..37839ca0 100644 --- a/lua/github-theme/lib/compiler.lua +++ b/lua/github-theme/lib/compiler.lua @@ -22,10 +22,14 @@ local function should_link(link) return link and link ~= '' end +---Compiles a single theme/style. `opts.theme` specifies the theme to compile, +---otherwise the currently-set theme will be compiled. +---@param opts? { theme: string } +---@return nil function M.compile(opts) opts = opts or {} - local theme = config.theme - local spec = require('github-theme.spec').load(theme) + opts.theme = opts.theme or config.theme + local spec = require('github-theme.spec').load(opts.theme) local groups = require('github-theme.group').from(spec) local background = spec.palette.meta.light and 'light' or 'dark' @@ -39,7 +43,7 @@ vim.o.termguicolors = true vim.g.colors_name = "%s" vim.o.background = "%s" ]], - theme, + opts.theme, background ), } @@ -68,8 +72,6 @@ vim.o.background = "%s" end table.insert(lines, 'end)') - - opts.name = theme local output_path, output_file = config.get_compiled_info(opts) util.ensure_dir(output_path) @@ -97,6 +99,7 @@ Bellow is the error message: tmpfile ) ) + local efile = io.open(tmpfile, 'wb') efile:write(table.concat(lines, '\n')) efile:close()