refactor(nvim): overhaul highlights
This commit is contained in:
parent
dbd8fb2d20
commit
eb98162264
@ -40,3 +40,15 @@
|
||||
!parameter
|
||||
contents: (contents) @markup.raw.block
|
||||
end_name: (expr) @org-block-end-name (#any-of? @org-block-end-name "src" "SRC"))
|
||||
|
||||
; Improved timestamp highlights
|
||||
(entry
|
||||
timestamp:
|
||||
(timestamp
|
||||
("<" @org.timestamp.active.delimiter)
|
||||
(">" @org.timestamp.active.delimiter)))
|
||||
(entry
|
||||
timestamp:
|
||||
(timestamp
|
||||
("[" @org.timestamp.inactive.delimiter)
|
||||
("]" @org.timestamp.inactive.delimiter)))
|
||||
|
@ -38,11 +38,12 @@ return {
|
||||
local palette = require("kanagawa.colors").setup()
|
||||
local colors = require("kanagawa.colors").setup().palette
|
||||
|
||||
-- This table was formed as an array to ensure the ordering of the keys. Since some
|
||||
-- HACK: This table was formed as an array to ensure the ordering of the keys. Since some
|
||||
-- highlights defined below depend on other highlights being correctly set, order is
|
||||
-- very important. Lua does not guarantee hashmaps will be in the order they are
|
||||
-- defined, thus the array.
|
||||
---@type { [1]: string, [2]: vim.api.keyset.highlight | fun(): vim.api.keyset.highlight }[]
|
||||
--
|
||||
---@type { [1]: string, [2]: vim.api.keyset.highlight | fun(): vim.api.keyset.highlight | table<Highlight.Keys, fun(): string | integer> }[]
|
||||
local extra_hls = {
|
||||
{ "NvimNotifyError", { fg = colors.samuraiRed } },
|
||||
{ "NvimNotifyWarn", { fg = colors.roninYellow } },
|
||||
@ -52,6 +53,10 @@ return {
|
||||
{ "Winbar", { bg = nil } },
|
||||
{ "StatusLineNC", { bg = nil } },
|
||||
{ "WinBarNC", { bg = nil } },
|
||||
{ "DiagnosticSignErrorCul", { link = "DiagnosticSignError" } },
|
||||
{ "DiagnosticSignWarnCul", { link = "DiagnosticSignWarn" } },
|
||||
{ "DiagnosticSignInfoCul", { link = "DiagnosticSignInfo" } },
|
||||
{ "DiagnosticSignHintCul", { link = "DiagnosticSignHint" } },
|
||||
{ "CursorLineNr", { fg = colors.roninYellow, bg = palette.theme.ui.bg_m1 } },
|
||||
{ "CursorLineFold", { fg = colors.crystalBlue, bg = palette.theme.ui.bg_m1 } },
|
||||
{ "CursorLineSign", { bg = palette.theme.ui.bg_m1 } },
|
||||
@ -217,23 +222,53 @@ return {
|
||||
{ "NotificationWarning", { link = "NvimNotifyWarn" } },
|
||||
{ "NotificationError", { link = "NvimNotifyError" } },
|
||||
|
||||
|
||||
-- Markup specific
|
||||
{ "@markup.raw", { fg = colors.carpYellow, bg = colors.sumiInk2 } },
|
||||
{ "@markup.raw.block", select_hl("@markup.raw", { "fg" }) },
|
||||
{ "@markup.raw.delimiter", { link = "@punctuation.delimiter" } },
|
||||
{ "CodeBlock", function() return { bg = get_hl("@markup.raw")().bg } end },
|
||||
{
|
||||
"CodeBlock",
|
||||
function()
|
||||
return { bg = get_hl("@markup.raw")().bg }
|
||||
end,
|
||||
},
|
||||
{ "Headline", { bg = colors.sumiInk0 } },
|
||||
{ "@markup.list.checked", { fg = colors.springGreen } },
|
||||
{ "@markup.list.indeterminate", { fg = colors.carpYellow } },
|
||||
{ "@markup.list.unchecked", { fg = colors.crystalBlue } },
|
||||
{ "@OrgTSCheckboxChecked.org", { link = "@markup.list.checked" } },
|
||||
{ "@OrgTSCheckboxHalfChecked.org", { link = "@markup.list.indeterminate" } },
|
||||
{ "@OrgTSCheckbox.org", { link = "@markup.list.unchecked" } },
|
||||
{ "org_verbatim", { fg = colors.springGreen, bg = colors.sumiInk0 } },
|
||||
{ "org_code", { link = "@markup.raw" } },
|
||||
{ "@OrgTSBlock.org", { fg = colors.fujiGray, bold = true, italic = true } },
|
||||
{ "@OrgTSDirective.org", { link = "@OrgTSBlock.org" } },
|
||||
{ "@markup.verbatim", { fg = colors.springGreen, bg = colors.sumiInk0 } },
|
||||
{ "@org.verbatim", { link = "@markup.verbatim" } },
|
||||
{ "@org.verbatim.delimiter", { link = "@markup.verbatim" } },
|
||||
{ "@org.timestamp", { underline = true, italic = false } },
|
||||
{ "@org.timestamp.active", get_hl("@org.timestamp", { fg = colors.springViolet1 }) },
|
||||
{
|
||||
"@org.timestamp.active.delimiter",
|
||||
{
|
||||
fg = function()
|
||||
return get_hl("@org.timestamp.active")().fg
|
||||
end,
|
||||
underline = false,
|
||||
nocombine = true,
|
||||
},
|
||||
},
|
||||
{
|
||||
"@org.timestamp.inactive",
|
||||
get_hl("@org.timestamp", {
|
||||
fg = function()
|
||||
return get_hl("@comment")().fg
|
||||
end,
|
||||
}),
|
||||
},
|
||||
{
|
||||
"@org.timestamp.inactive.delimiter",
|
||||
{
|
||||
fg = function()
|
||||
return get_hl("@org.timestamp.inactive")().fg
|
||||
end,
|
||||
underline = false,
|
||||
nocombine = true,
|
||||
},
|
||||
},
|
||||
|
||||
-- Titles/Headlines
|
||||
{ "@markup.heading.1", { fg = colors.crystalBlue, bold = true } },
|
||||
@ -267,31 +302,44 @@ return {
|
||||
vim.iter(extra_hls):enumerate():fold({}, function(t, index, tbl)
|
||||
local hl_name = tbl[1]
|
||||
local hl_opts = tbl[2]
|
||||
local wrapper = function()
|
||||
if t[hl_name] then
|
||||
vim.notify(string.format("Duplicate highlight '%s' defined at index '%d'!", hl_name, index),
|
||||
vim.log.levels.ERROR)
|
||||
vim.notify(
|
||||
string.format("Duplicate highlight '%s' defined at index '%d'!", hl_name, index),
|
||||
vim.log.levels.ERROR
|
||||
)
|
||||
end
|
||||
|
||||
if type(hl_opts) == "function" then
|
||||
hl_opts = hl_opts()
|
||||
end
|
||||
hl_opts = vim.iter(hl_opts):fold({}, function(hl_t, k, v)
|
||||
if type(v) == "function" then
|
||||
v = v()
|
||||
end
|
||||
hl_t[k] = v
|
||||
return hl_t
|
||||
end)
|
||||
if hl_opts.force == nil then
|
||||
vim.tbl_deep_extend("force", hl_opts, { force = true })
|
||||
end
|
||||
local success, err = pcall(vim.api.nvim_set_hl, 0, hl_name, hl_opts)
|
||||
vim.api.nvim_set_hl(0, hl_name, hl_opts)
|
||||
t[hl_name] = true
|
||||
return t
|
||||
end
|
||||
local success, result = pcall(wrapper)
|
||||
if not success then
|
||||
vim.notify(
|
||||
string.format(
|
||||
"Failed to set highlight for '%s', err: '%s' ... Table:\n%s",
|
||||
hl_name,
|
||||
err,
|
||||
result,
|
||||
vim.inspect(hl_opts)
|
||||
),
|
||||
vim.log.levels.ERROR
|
||||
)
|
||||
end
|
||||
t[hl_name] = true
|
||||
return t
|
||||
return result
|
||||
end)
|
||||
end,
|
||||
},
|
||||
|
@ -51,18 +51,6 @@ U.title_case = function(str)
|
||||
return string.gsub(str, "(%a)([%w_']*)", inner)
|
||||
end
|
||||
|
||||
---Get the effective given highlight, optionally overriding some of its fields
|
||||
---@param name string Highlight name
|
||||
---@param opts? vim.api.keyset.highlight
|
||||
---@return fun(): vim.api.keyset.highlight
|
||||
U.get_hl = function(name, opts)
|
||||
---@return vim.api.keyset.highlight
|
||||
return function()
|
||||
---@diagnostic disable-next-line: return-type-mismatch
|
||||
return vim.tbl_deep_extend("force", vim.api.nvim_get_hl(0, { name = name, link = false }), opts or {})
|
||||
end
|
||||
end
|
||||
|
||||
---@alias Highlight.Keys
|
||||
---| '"bold"'
|
||||
---| '"standout"'
|
||||
@ -95,6 +83,25 @@ end
|
||||
---| '"force"'
|
||||
---| '"url"'
|
||||
|
||||
---Get the effective given highlight, optionally overriding some of its fields
|
||||
---@param name string Highlight name
|
||||
---@param opts? vim.api.keyset.highlight | table<Highlight.Keys, fun(): string | integer>
|
||||
---@return fun(): vim.api.keyset.highlight
|
||||
U.get_hl = function(name, opts)
|
||||
opts = vim.iter(opts or {}):fold({}, function(t, k, v)
|
||||
if type(v) == "function" then
|
||||
v = v()
|
||||
end
|
||||
t[k] = v
|
||||
return t
|
||||
end)
|
||||
---@return vim.api.keyset.highlight
|
||||
return function()
|
||||
---@diagnostic disable-next-line: return-type-mismatch
|
||||
return vim.tbl_deep_extend("force", vim.api.nvim_get_hl(0, { name = name, link = false }), opts or {})
|
||||
end
|
||||
end
|
||||
|
||||
---Get only the specified items from the highlight
|
||||
---@param name string Highlight name
|
||||
---@param fields Highlight.Keys[]
|
||||
|
Loading…
Reference in New Issue
Block a user