From 4db28ae6449168e2947c4f966cdd4feefc310216 Mon Sep 17 00:00:00 2001 From: Johan Restrepo <62318029+JohanRestrepo19@users.noreply.github.com> Date: Sat, 16 Mar 2024 14:22:28 -0500 Subject: [PATCH] feat(syntax)!: add additional syntax styles. Introduce new styles options in order to be able to customize a bit more the rose pine colorscheme syntax and not depend exclusively on italic and bold style options. A new utility function was added in order to add a custom hl property style for custom syntax styles. --- lua/rose-pine.lua | 18 +++++++++--------- lua/rose-pine/config.lua | 4 ++++ lua/rose-pine/utilities.lua | 10 ++++++++++ 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/lua/rose-pine.lua b/lua/rose-pine.lua index 14d6bb8..f98cd8a 100644 --- a/lua/rose-pine.lua +++ b/lua/rose-pine.lua @@ -179,7 +179,7 @@ local function set_highlights() Boolean = { fg = palette.rose }, Character = { fg = palette.gold }, - Comment = { fg = palette.subtle, italic = styles.italic }, + Comment = { fg = palette.subtle, style = styles.comments }, Conditional = { fg = palette.pine }, Constant = { fg = palette.gold }, Debug = { fg = palette.rose }, @@ -188,10 +188,10 @@ local function set_highlights() Error = { fg = palette.love }, Exception = { fg = palette.pine }, Float = { fg = palette.gold }, - Function = { fg = palette.rose }, - Identifier = { fg = palette.text }, + Function = { fg = palette.rose, style = styles.functions }, + Identifier = { fg = palette.text, style = styles.variables }, Include = { fg = palette.pine }, - Keyword = { fg = palette.pine }, + Keyword = { fg = palette.pine, style = styles.keywords }, Label = { fg = palette.foam }, LspCodeLens = { fg = palette.subtle }, LspCodeLensSeparator = { fg = palette.muted }, @@ -266,9 +266,9 @@ local function set_highlights() mkdURL = { link = "markdownUrl" }, --- Identifiers - ["@variable"] = { fg = palette.text, italic = styles.italic }, - ["@variable.builtin"] = { fg = palette.love, bold = styles.bold }, - ["@variable.parameter"] = { fg = palette.iris, italic = styles.italic }, + ["@variable"] = { fg = palette.text, style = styles.variables }, + ["@variable.builtin"] = { fg = palette.love }, + ["@variable.parameter"] = { fg = palette.iris }, ["@variable.member"] = { fg = palette.foam }, ["@constant"] = { fg = palette.gold }, @@ -303,7 +303,7 @@ local function set_highlights() -- ["@type.qualifier"] = {}, -- ["@attribute"] = {}, - ["@property"] = { fg = palette.foam, italic = styles.italic }, + ["@property"] = { fg = palette.foam, style = styles.variables }, --- Functions ["@function"] = { fg = palette.rose }, @@ -857,7 +857,7 @@ local function set_highlights() if highlight.blend ~= nil and (highlight.blend >= 0 and highlight.blend <= 100) and highlight.bg ~= nil then highlight.bg = utilities.blend(highlight.bg, highlight.blend_on or palette.base, highlight.blend / 100) end - vim.api.nvim_set_hl(0, group, highlight) + utilities.highlight(group, highlight) end --- Terminal diff --git a/lua/rose-pine/config.lua b/lua/rose-pine/config.lua index 562d2a4..40653a8 100644 --- a/lua/rose-pine/config.lua +++ b/lua/rose-pine/config.lua @@ -30,6 +30,10 @@ config.options = { }, styles = { + comments = { italic = true }, + functions = {}, + keywords = { italic = true }, + variables = {}, bold = true, italic = true, transparency = false, diff --git a/lua/rose-pine/utilities.lua b/lua/rose-pine/utilities.lua index 26e019e..31d198b 100644 --- a/lua/rose-pine/utilities.lua +++ b/lua/rose-pine/utilities.lua @@ -44,4 +44,14 @@ function utilities.blend(fg, bg, alpha) return string.format("#%02X%02X%02X", blend_channel(1), blend_channel(2), blend_channel(3)) end +---@param group string +---@param hl table +function utilities.highlight(group, hl) + if hl.style then + hl = vim.tbl_extend("force", hl, hl.style) + hl.style = nil + end + vim.api.nvim_set_hl(0, group, hl) +end + return utilities