Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
Refactor override function to util.lua module #91
Browse files Browse the repository at this point in the history
Other Changes:
- Removed unnecessary defer function & highlights
  • Loading branch information
ful1e5 committed Dec 22, 2021
1 parent b7201d3 commit 7342326
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 45 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- plugin support [coc.nvim](https://github.com/neoclide/coc.nvim)
- define global in project `luarc` config file.
- config option added `hide_end_of_buffer`
- allow customizing highlight group #91
- Removed unnecessary defer function & highlights

### Changed

Expand All @@ -22,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `TSTagAttribute` highlight added
- yellow changed to the same version as onedark palette. monsonjeremy/onedark.nvim#19
- Boolean set to orange as in VSC onedark theme. monsonjeremy/onedark.nvim#19
- refactor override function to util.lua module #91

## [v0.0.3]- 11 Dec 2021

Expand Down
37 changes: 19 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,24 @@ require('lualine').setup {

## Configuration

| Option | Default | Description |
| ------------------------ | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| colors | `{}` | You can override specific color groups to use other groups or a hex color |
| comment_style | `italic` | Highlight style for comments (check `:help highlight-args` for options) |
| dark_float | `true` | Float windows like the lsp diagnostics windows get a darker background. |
| dark_sidebar | `true` | Sidebar like windows like `NvimTree` get a darker background |
| function_style | `NONE` | Highlight style for functions (check `:help highlight-args` for options) |
| hide_end_of_buffer | `true` | Enabling this option, will hide filler lines (~) after the end of the buffer |
| hide_inactive_statusline | `false` | Enabling this option, will hide inactive statuslines and replace them with a thin border instead. Should work with the standard **StatusLine**. |
| highlight_linenumber | `false` | Enabling this option, will enable dark color to `LineNr`, `SignColumn` and `CursorLineNr` highlights.(also support [gitsigns](https://github.com/lewis6991/gitsigns.nvim) plugin) |
| keyword_style | `italic` | Highlight style for keywords (check `:help highlight-args` for options) |
| lualine_bold | `false` | When `true`, section headers in the lualine theme will be bold |
| msg_area_style | `NONE` | Highlight style for messages and cmdline (check `:help highlight-args` for options) |
| overrides | `function` | Override specific highlight groups. The function accpet colors as argument. |
| sidebars | `{}` | Set a darker background on sidebar-like windows. For example: `{"qf", "vista_kind", "terminal", "packer"}` |
| transparent | `false` | Enable this to disable setting the background color |
| transparent_sidebar | `false` | Sidebar like windows like `NvimTree` get a transparent background |
| variable_style | `NONE` | Highlight style for variables and identifiers (check `:help highlight-args` for options) |
| Option | Default | Description |
| ------------------------ | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| colors | `{}` | You can override specific color groups to use other groups or a hex color |
| comment_style | `italic` | Highlight style for comments (check `:help highlight-args` for options) |
| dark_float | `true` | Float windows like the lsp diagnostics windows get a darker background. |
| dark_sidebar | `true` | Sidebar like windows like `NvimTree` get a darker background |
| function_style | `NONE` | Highlight style for functions (check `:help highlight-args` for options) |
| hide_end_of_buffer | `true` | Enabling this option, will hide filler lines (~) after the end of the buffer |
| hide_inactive_statusline | `false` | Enabling this option, will hide inactive statuslines and replace them with a thin border instead. Should work with the standard **StatusLine**. |
| highlight_linenumber | `false` | Enabling this option, will enable dark color to `LineNr`, `SignColumn` and `CursorLineNr` highlights.(also support [gitsigns](https://github.com/lewis6991/gitsigns.nvim) plugin) |
| keyword_style | `italic` | Highlight style for keywords (check `:help highlight-args` for options) |
| lualine_bold | `false` | When `true`, section headers in the lualine theme will be bold |
| msg_area_style | `NONE` | Highlight style for messages and cmdline (check `:help highlight-args` for options) |
| overrides | `function` | Override specific highlight groups. The function accpet colors as argument. |
| sidebars | `{}` | Set a darker background on sidebar-like windows. For example: `{"qf", "vista_kind", "terminal", "packer"}` |
| transparent | `false` | Enable this to disable setting the background color |
| transparent_sidebar | `false` | Sidebar like windows like `NvimTree` get a transparent background |
| variable_style | `NONE` | Highlight style for variables and identifiers (check `:help highlight-args` for options) |

```vim
" Example config in VimScript
Expand All @@ -150,6 +150,7 @@ require("onedark").setup({

-- Change the "hint" color to the "orange" color, and make the "error" color bright red
colors = {hint = "orange", error = "#ff0000"},

-- Overwrite the highlight groups
overrides = function(c)
return {
Expand Down
4 changes: 3 additions & 1 deletion lua/onedark/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ local config = {
keyword_style = opt("keyword_style", "italic"),
lualine_bold = opt("lualine_bold", false),
msg_area_style = opt("msg_area_style", "NONE"),
overrides = opt("overrides", function() return {} end),
overrides = opt("overrides", function()
return {}
end),
sidebars = opt("sidebars", {}),
transform_colors = false,
transparent = opt("transparent", false),
Expand Down
19 changes: 4 additions & 15 deletions lua/onedark/theme.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ local config_module = require("onedark.config")

local M = {}

local function apply_overrides(group, overrides)
for k, v in pairs(overrides) do
if group[k] ~= nil and type(v) == "table" then
group[k] = v
end
end
end

---@param config onedark.Config
---@return onedark.Theme
function M.setup(config)
Expand Down Expand Up @@ -594,13 +586,6 @@ function M.setup(config)
CocUnderline = {style = "undercurl"}
}

theme.defer = {}

local overrides = config.overrides(c)
apply_overrides(theme.base, overrides)
apply_overrides(theme.plugins, overrides)
apply_overrides(theme.defer, overrides)

if config.hide_inactive_statusline then

-- StatusLine
Expand All @@ -616,6 +601,10 @@ function M.setup(config)
end
end

local overrides = config.overrides(c)
util.apply_overrides(theme.base, overrides)
util.apply_overrides(theme.plugins, overrides)

return theme
end

Expand Down
24 changes: 13 additions & 11 deletions lua/onedark/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ end

-- local ns = vim.api.nvim_create_namespace("onedark")
function util.highlight(group, color)
if not (color.fg or color.bg or color.sp or color.style or color.link) then
return
end
if not (color.fg or color.bg or color.sp or color.style or color.link) then return end

if color.fg then util.colorsUsed[color.fg] = true end
if color.bg then util.colorsUsed[color.bg] = true end
Expand Down Expand Up @@ -206,6 +204,15 @@ function util.light_colors(colors)
return ret
end

---Override custom highlights in `group`
---@param group table
---@param overrides table
function util.apply_overrides(group, overrides)
for k, v in pairs(overrides) do
if group[k] ~= nil and type(v) == "table" then group[k] = v end
end
end

---@param theme onedark.Theme
function util.load(theme)
vim.cmd("hi clear")
Expand All @@ -217,14 +224,9 @@ function util.load(theme)

-- load base theme
util.syntax(theme.base)

-- load syntax for plugins and terminal async
vim.defer_fn(function()
util.autocmds(theme.config)
util.terminal(theme.colors)
util.syntax(theme.plugins)
util.syntax(theme.defer)
end, 100)
util.autocmds(theme.config)
util.terminal(theme.colors)
util.syntax(theme.plugins)
end

---@param colors onedark.ColorScheme
Expand Down

0 comments on commit 7342326

Please sign in to comment.