From 7342326b87e5fcc172da99a1dd2c4d2b8c91c6ef Mon Sep 17 00:00:00 2001 From: ful1e5 <24286590+ful1e5@users.noreply.github.com> Date: Wed, 22 Dec 2021 15:55:02 +0530 Subject: [PATCH] Refactor override function to util.lua module #91 Other Changes: - Removed unnecessary defer function & highlights --- CHANGELOG.md | 3 +++ README.md | 37 +++++++++++++++++++------------------ lua/onedark/config.lua | 4 +++- lua/onedark/theme.lua | 19 ++++--------------- lua/onedark/util.lua | 24 +++++++++++++----------- 5 files changed, 42 insertions(+), 45 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10ac908..fb9ee9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 diff --git a/README.md b/README.md index fd18dcf..2f3da88 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 { diff --git a/lua/onedark/config.lua b/lua/onedark/config.lua index d05b4a8..5457cd0 100644 --- a/lua/onedark/config.lua +++ b/lua/onedark/config.lua @@ -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), diff --git a/lua/onedark/theme.lua b/lua/onedark/theme.lua index 36008dc..eb5b5ca 100644 --- a/lua/onedark/theme.lua +++ b/lua/onedark/theme.lua @@ -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) @@ -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 @@ -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 diff --git a/lua/onedark/util.lua b/lua/onedark/util.lua index e8733b3..0a2b7d4 100644 --- a/lua/onedark/util.lua +++ b/lua/onedark/util.lua @@ -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 @@ -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") @@ -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