Skip to content

Commit

Permalink
refactor: use hi-default (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
fitrh authored Jul 5, 2022
1 parent b1cea68 commit 3188692
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
8 changes: 4 additions & 4 deletions lua/modes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ M.define = function()

for _, mode in ipairs({ 'Copy', 'Delete', 'Insert', 'Visual' }) do
local def = { bg = blended_colors[mode:lower()] }
utils.set_hl(('Modes%sCursorLine'):format(mode), def, true)
utils.set_hl(('Modes%sCursorLineNr'):format(mode), def, true)
utils.set_hl(('Modes%sCursorLineSign'):format(mode), def, true)
utils.set_hl(('Modes%sCursorLineFold'):format(mode), def, true)
utils.set_hl(('Modes%sCursorLine'):format(mode), def)
utils.set_hl(('Modes%sCursorLineNr'):format(mode), def)
utils.set_hl(('Modes%sCursorLineSign'):format(mode), def)
utils.set_hl(('Modes%sCursorLineFold'):format(mode), def)
end

utils.set_hl('ModesInsertModeMsg', { fg = colors.insert })
Expand Down
11 changes: 2 additions & 9 deletions lua/modes/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ end
---Set highlight
---@param name string
---@param color Color
---@param if_not_exists? boolean
M.set_hl = function(name, color, if_not_exists)
M.set_hl = function(name, color)
if color.link ~= nil then
vim.cmd('hi ' .. name .. ' guibg=none guifg=none')
vim.cmd('hi! link ' .. name .. ' ' .. color.link)
Expand All @@ -58,13 +57,7 @@ M.set_hl = function(name, color, if_not_exists)
local bg = color.bg or 'none'
local fg = color.fg or 'none'

if if_not_exists then
if pcall(vim.api.nvim_get_hl_by_name, name, true) then
return
end
end

vim.cmd('hi ' .. name .. ' guibg=' .. bg .. ' guifg=' .. fg)
vim.cmd('hi default ' .. name .. ' guibg=' .. bg .. ' guifg=' .. fg)
end

M.get_fg = function(name, fallback)
Expand Down

0 comments on commit 3188692

Please sign in to comment.