From 770d1b51ecbab04d4448b8303ad45e6ea446ef79 Mon Sep 17 00:00:00 2001 From: Tyler Miller Date: Wed, 7 Aug 2024 05:37:51 -0700 Subject: [PATCH] refactor: minify colorscheme files in `colors/*.vim` Refactor and centralize all of the duplicated logic in each of the vim files in `colors/*.vim` into `require('github-theme').load()`. This removes duplication and moves all of the logic to Lua (file) where it is easier to maintain. Remove the deprecated 'github_dimmed' theme. This has been deprecated for over a year now, so it is probably a good idea to remove it. Plus it just wastes space and pollutes cmdline completion with an erroneous value/theme. --- CHANGELOG.md | 5 +++++ colors/github_dark.vim | 10 +--------- colors/github_dark_colorblind.vim | 10 +--------- colors/github_dark_default.vim | 10 +--------- colors/github_dark_dimmed.vim | 10 +--------- colors/github_dark_high_contrast.vim | 10 +--------- colors/github_dark_tritanopia.vim | 10 +--------- colors/github_dimmed.vim | 18 ------------------ colors/github_light.vim | 10 +--------- colors/github_light_colorblind.vim | 10 +--------- colors/github_light_default.vim | 10 +--------- colors/github_light_high_contrast.vim | 10 +--------- colors/github_light_tritanopia.vim | 10 +--------- lua/github-theme/config.lua | 8 +++----- lua/github-theme/init.lua | 9 +++++++++ lua/lualine/themes/github_dimmed.lua | 1 - 16 files changed, 28 insertions(+), 123 deletions(-) delete mode 100644 colors/github_dimmed.vim delete mode 100644 lua/lualine/themes/github_dimmed.lua diff --git a/CHANGELOG.md b/CHANGELOG.md index a3d992a3..0e2b4495 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic ## [unreleased] +### Changes + +- Minimized colorscheme files in `colors/*.vim` and refactored-out duplicated logic +- Removed the long-since deprecated `github_dimmed` theme (use `github_dark_dimmed` instead) + ### Issues Fix - Fixed JSX/TSX tags are missing highlights with nvim 0.10 (#360) diff --git a/colors/github_dark.vim b/colors/github_dark.vim index 21981587..54feb644 100644 --- a/colors/github_dark.vim +++ b/colors/github_dark.vim @@ -1,9 +1 @@ -lua << EOF - -if vim.g.github_theme_debug then - require('github-theme.util.reload')() -end -require('github-theme.config').set_theme('github_dark') -require('github-theme').load() - -EOF +lua require('github-theme').load({ theme = 'github_dark' }) diff --git a/colors/github_dark_colorblind.vim b/colors/github_dark_colorblind.vim index 50ec19c6..6084849f 100644 --- a/colors/github_dark_colorblind.vim +++ b/colors/github_dark_colorblind.vim @@ -1,9 +1 @@ -lua << EOF - -if vim.g.github_theme_debug then - require('github-theme.util.reload')() -end -require('github-theme.config').set_theme('github_dark_colorblind') -require('github-theme').load() - -EOF +lua require('github-theme').load({ theme = 'github_dark_colorblind' }) diff --git a/colors/github_dark_default.vim b/colors/github_dark_default.vim index 27c302dc..1b670d36 100644 --- a/colors/github_dark_default.vim +++ b/colors/github_dark_default.vim @@ -1,9 +1 @@ -lua << EOF - -if vim.g.github_theme_debug then - require('github-theme.util.reload')() -end -require('github-theme.config').set_theme('github_dark_default') -require('github-theme').load() - -EOF +lua require('github-theme').load({ theme = 'github_dark_default' }) diff --git a/colors/github_dark_dimmed.vim b/colors/github_dark_dimmed.vim index b6c7d42b..f430612c 100644 --- a/colors/github_dark_dimmed.vim +++ b/colors/github_dark_dimmed.vim @@ -1,9 +1 @@ -lua << EOF - -if vim.g.github_theme_debug then - require('github-theme.util.reload')() -end -require('github-theme.config').set_theme('github_dark_dimmed') -require('github-theme').load() - -EOF +lua require('github-theme').load({ theme = 'github_dark_dimmed' }) diff --git a/colors/github_dark_high_contrast.vim b/colors/github_dark_high_contrast.vim index bd1221d1..a8adb83e 100644 --- a/colors/github_dark_high_contrast.vim +++ b/colors/github_dark_high_contrast.vim @@ -1,9 +1 @@ -lua << EOF - -if vim.g.github_theme_debug then - require('github-theme.util.reload')() -end -require('github-theme.config').set_theme('github_dark_high_contrast') -require('github-theme').load() - -EOF +lua require('github-theme').load({ theme = 'github_dark_high_contrast' }) diff --git a/colors/github_dark_tritanopia.vim b/colors/github_dark_tritanopia.vim index 637589a5..4411854e 100644 --- a/colors/github_dark_tritanopia.vim +++ b/colors/github_dark_tritanopia.vim @@ -1,9 +1 @@ -lua << EOF - -if vim.g.github_theme_debug then - require('github-theme.util.reload')() -end -require('github-theme.config').set_theme('github_dark_tritanopia') -require('github-theme').load() - -EOF +lua require('github-theme').load({ theme = 'github_dark_tritanopia' }) diff --git a/colors/github_dimmed.vim b/colors/github_dimmed.vim deleted file mode 100644 index 58610141..00000000 --- a/colors/github_dimmed.vim +++ /dev/null @@ -1,18 +0,0 @@ -lua << EOF - -local dep = require('github-theme.lib.deprecation') -dep.write( - ' Colorscheme ', - { 'github_dimmed', 'WarningMsg' }, - ' has been deprecated.', - ' Use ', - { 'github_dark_dimmed', 'WarningMsg' }, - ' Instead. Refer to ', - { ':h github-theme.changelog-23042023', 'WarningMsg' }, - ' for more info.' -) - -require('github-theme.config').set_theme('github_dark_dimmed') -require('github-theme').load() - -EOF diff --git a/colors/github_light.vim b/colors/github_light.vim index 144e8a2f..8591956b 100644 --- a/colors/github_light.vim +++ b/colors/github_light.vim @@ -1,9 +1 @@ -lua << EOF - -if vim.g.github_theme_debug then - require('github-theme.util.reload')() -end -require('github-theme.config').set_theme('github_light') -require('github-theme').load() - -EOF +lua require('github-theme').load({ theme = 'github_light' }) diff --git a/colors/github_light_colorblind.vim b/colors/github_light_colorblind.vim index 2edd1d6d..53e3f13c 100644 --- a/colors/github_light_colorblind.vim +++ b/colors/github_light_colorblind.vim @@ -1,9 +1 @@ -lua << EOF - -if vim.g.github_theme_debug then - require('github-theme.util.reload')() -end -require('github-theme.config').set_theme('github_light_colorblind') -require('github-theme').load() - -EOF +lua require('github-theme').load({ theme = 'github_light_colorblind' }) diff --git a/colors/github_light_default.vim b/colors/github_light_default.vim index 658e13fe..df9cd208 100644 --- a/colors/github_light_default.vim +++ b/colors/github_light_default.vim @@ -1,9 +1 @@ -lua << EOF - -if vim.g.github_theme_debug then - require('github-theme.util.reload')() -end -require('github-theme.config').set_theme('github_light_default') -require('github-theme').load() - -EOF +lua require('github-theme').load({ theme = 'github_light_default' }) diff --git a/colors/github_light_high_contrast.vim b/colors/github_light_high_contrast.vim index 911961ef..112d193b 100644 --- a/colors/github_light_high_contrast.vim +++ b/colors/github_light_high_contrast.vim @@ -1,9 +1 @@ -lua << EOF - -if vim.g.github_theme_debug then - require('github-theme.util.reload')() -end -require('github-theme.config').set_theme('github_light_high_contrast') -require('github-theme').load() - -EOF +lua require('github-theme').load({ theme = 'github_light_high_contrast' }) diff --git a/colors/github_light_tritanopia.vim b/colors/github_light_tritanopia.vim index ededae6f..0d103e00 100644 --- a/colors/github_light_tritanopia.vim +++ b/colors/github_light_tritanopia.vim @@ -1,9 +1 @@ -lua << EOF - -if vim.g.github_theme_debug then - require('github-theme.util.reload')() -end -require('github-theme.config').set_theme('github_light_tritanopia') -require('github-theme').load() - -EOF +lua require('github-theme').load({ theme = 'github_light_tritanopia' }) diff --git a/lua/github-theme/config.lua b/lua/github-theme/config.lua index 5a3bc32c..fad100cc 100644 --- a/lua/github-theme/config.lua +++ b/lua/github-theme/config.lua @@ -150,8 +150,6 @@ local defaults = { }, } -M.options = collect.deep_copy(defaults) - M.module_names = { 'cmp', 'coc', @@ -193,6 +191,7 @@ end function M.reset() M.options = collect.deep_copy(defaults) + return M end function M.get_compiled_info(opts) @@ -203,8 +202,7 @@ function M.get_compiled_info(opts) end function M.hash() - local hash = require('github-theme.lib.hash')(M.options) - return hash or 0 + return require('github-theme.lib.hash')(M.options) or 0 end -return M +return M.reset() diff --git a/lua/github-theme/init.lua b/lua/github-theme/init.lua index 9f68d93f..143d93fd 100644 --- a/lua/github-theme/init.lua +++ b/lua/github-theme/init.lua @@ -74,6 +74,15 @@ end function M.load(opts) opts = opts or {} + + if vim.g.github_theme_debug then + require('github-theme.util.reload')() + end + + if opts.theme then + require('github-theme.config').set_theme(opts.theme) + end + local _, compiled_file = config.get_compiled_info(opts) local f = loadfile(compiled_file) diff --git a/lua/lualine/themes/github_dimmed.lua b/lua/lualine/themes/github_dimmed.lua deleted file mode 100644 index 69f8a6a4..00000000 --- a/lua/lualine/themes/github_dimmed.lua +++ /dev/null @@ -1 +0,0 @@ -return require('github-theme.util.lualine')('github_dark_dimmed')