forked from projekt0n/github-nvim-theme
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(overrides): improve highlight-group overrides (projekt0n#349)
- Assigning `false` or an empty table to a highlight group clears it - Assigning `false` to groups/specs/palettes clears previous settings from the config store (like `reset()` but finer-grained) - (internal) Use `false` instead of `link = ''` to mark groups which should be cleared when set - Improve `github-theme.group` - Improve/cleanup code and other minor improvements (code-sharing, simplification, etc.)
- Loading branch information
Showing
9 changed files
with
178 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
local function reload() | ||
for name, _ in pairs(package.loaded) do | ||
if name:match('^github-theme') then | ||
---@param force? boolean | ||
local function reload(force) | ||
for name, _ in pairs(_G.package.loaded) do | ||
if name:find('^github%-theme') then | ||
if | ||
not name:match('config') | ||
and not name:match('deprecation') | ||
and not name:match('override') | ||
force | ||
or ( | ||
not name:find('config') | ||
and not name:find('deprecation') | ||
and not name:find('override') | ||
) | ||
then | ||
package.loaded[name] = nil | ||
_G.package.loaded[name] = nil | ||
end | ||
end | ||
end | ||
end | ||
|
||
return setmetatable({}, { | ||
__call = function(_) | ||
reload() | ||
__call = function(_, ...) | ||
reload(...) | ||
end, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
local assert = require('luassert') | ||
local t_util = require('github-theme._test.util') | ||
|
||
if vim.fn.has('nvim-0.9.0') == 0 or vim.fn.has('nvim-0.9.0') == false then | ||
return | ||
end | ||
|
||
describe('config > groups', function() | ||
before_each(function() | ||
require('github-theme.util.reload')(true) | ||
end) | ||
|
||
it('should allow clearing a group via empty table (1)', function() | ||
require('github-theme').setup({ groups = { all = { Normal = {} } } }) | ||
vim.cmd.colorscheme({ args = { 'github_dark_dimmed' } }) | ||
assert.same({}, t_util.get_hl('Normal')) | ||
end) | ||
|
||
it('should allow clearing a group via empty table (2)', function() | ||
require('github-theme').setup({ | ||
groups = { | ||
github_dark_dimmed = { Normal = {} }, | ||
all = { Normal = { fg = '#123456', bg = '#654321' } }, | ||
}, | ||
}) | ||
vim.cmd.colorscheme({ args = { 'github_dark_dimmed' } }) | ||
assert.same({}, t_util.get_hl('Normal')) | ||
end) | ||
|
||
it('clearing group combines properly with more-specific overrides', function() | ||
require('github-theme').setup({ | ||
groups = { | ||
all = { Normal = {} }, | ||
github_dark_dimmed = { Normal = { fg = '#123456', bg = '#654321' } }, | ||
}, | ||
}) | ||
vim.cmd.colorscheme({ args = { 'github_dark_dimmed' } }) | ||
assert.same( | ||
{ fg = tonumber('123456', 16), bg = tonumber('654321', 16) }, | ||
t_util.get_hl('Normal') | ||
) | ||
end) | ||
|
||
it('should allow overriding a group', function() | ||
require('github-theme').setup({ | ||
groups = { all = { Normal = { fg = '#123456', bg = '#654321' } } }, | ||
}) | ||
vim.cmd.colorscheme({ args = { 'github_dark_dimmed' } }) | ||
assert.same( | ||
{ fg = tonumber('123456', 16), bg = tonumber('654321', 16) }, | ||
t_util.get_hl('Normal') | ||
) | ||
end) | ||
|
||
it('overriding group combines properly with more-specific overrides (1)', function() | ||
require('github-theme').setup({ | ||
groups = { | ||
all = { Normal = { link = 'NormalNC' } }, | ||
github_dark_dimmed = { Normal = { fg = '#123456', bg = '#654321' } }, | ||
}, | ||
}) | ||
vim.cmd.colorscheme({ args = { 'github_dark_dimmed' } }) | ||
assert.is_nil(t_util.get_hl('Normal', true).link) | ||
end) | ||
|
||
it('overriding group combines properly with more-specific overrides (2)', function() | ||
require('github-theme').setup({ | ||
groups = { | ||
all = { Normal = { fg = '#123456', bg = '#654321' } }, | ||
github_dark_dimmed = { Normal = { link = 'NormalNC' } }, | ||
}, | ||
}) | ||
vim.cmd.colorscheme({ args = { 'github_dark_dimmed' } }) | ||
assert.same({ link = 'NormalNC' }, t_util.get_hl('Normal', true)) | ||
end) | ||
|
||
it('should allow linking a group', function() | ||
require('github-theme').setup({ | ||
groups = { all = { Normal = { link = 'NormalNC' } } }, | ||
}) | ||
vim.cmd.colorscheme({ args = { 'github_dark_dimmed' } }) | ||
assert.same({ link = 'NormalNC' }, t_util.get_hl('Normal', true)) | ||
end) | ||
|
||
it('should not be affected by a previous override using `link`', function() | ||
require('github-theme').setup({ | ||
groups = { | ||
all = { Normal = { link = 'NormalNC' } }, | ||
}, | ||
}) | ||
require('github-theme').setup({ | ||
groups = { | ||
all = { Normal = { fg = '#123456', bg = '#654321' } }, | ||
}, | ||
}) | ||
|
||
vim.cmd.colorscheme({ args = { 'github_dark_dimmed' } }) | ||
assert.same( | ||
{ fg = '#123456', bg = '#654321' }, | ||
require('github-theme.override').groups.all.Normal | ||
) | ||
assert.is_nil(t_util.get_hl('Normal', true).link) | ||
assert.same( | ||
{ fg = tonumber('123456', 16), bg = tonumber('654321', 16) }, | ||
t_util.get_hl('Normal') | ||
) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
lua vim.loader.disable() | ||
lua << | ||
if vim.fn.has('nvim-0.9.0') == 1 or vim.fn.has('nvim-0.9.0') == true then | ||
vim.loader.disable() | ||
end | ||
. | ||
set rtp+=. | ||
set rtp+=./test/plenary | ||
runtime! plugin/plenary.vim |