From 08ba0780ae7fa4e21f488b21dae6469c1cbd7a07 Mon Sep 17 00:00:00 2001 From: Iron_E Date: Thu, 19 Nov 2020 16:53:35 -0500 Subject: [PATCH] Simplify highlite.group --- lua/highlite.lua | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lua/highlite.lua b/lua/highlite.lua index 2ad034d..8afe262 100644 --- a/lua/highlite.lua +++ b/lua/highlite.lua @@ -43,6 +43,14 @@ local function blend(command, attributes) -- {{{ † end end --}}} ‡ +-- filter a highlight group's style information +local function filter_group_style(value) + return value ~= 'background' + and value ~= 'blend' + and value ~= 'foreground' + and value ~= 'special' +end + -- Get the color value of a color variable, or "NONE" as a default. local function get(color, index) -- {{{ † if type(color) == _TYPE_TABLE and color[index] then @@ -94,17 +102,13 @@ function highlite.group(group_name) if not no_errors then group_definition = {} end + -- the string.fmt expression to convert RGB to HEX local fmt = '#%06x' - local style = {} - if group_definition.bold then style[#style+1] = 'bold' end - if group_definition.italic then style[#style+1] = 'italic' end - if group_definition.reverse then style[#style+1] = 'reverse' end - if group_definition.strikethrough then style[#style+1] = 'strikethrough' end - if group_definition.undercurl then style[#style+1] = 'undercurl' end - if group_definition.underline then style[#style+1] = 'underline' end - if group_definition.special then style.color = - string.format(fmt, group_definition.special) + -- the style of the highlight group + local style = vim.tbl_filter(filter_group_style, vim.tbl_keys(group_definition)) + if group_definition.special then + style.color = string.format(fmt, group_definition.special) end return {