Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 31 additions & 10 deletions lua/monokai.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,33 @@ M.soda = {
diff_text = '#23324d',
}

M.highlight = function(group, color)
local style = color.style and 'gui=' .. color.style or 'gui=NONE'
local fg = color.fg and 'guifg = ' .. color.fg or 'guifg = NONE'
local bg = color.bg and 'guibg = ' .. color.bg or 'guibg = NONE'
local sp = color.sp and 'guisp = ' .. color.sp or ''
vim.cmd(
'highlight ' .. group .. ' ' .. style .. ' ' .. fg .. ' ' .. bg .. ' ' .. sp
)
local function maybe_remove_italics(config, colors)
if not config.italics and colors.style == 'italic' then
colors.style = nil
end
return colors
end

local function highlighter(config)
return function(group, color)
color = maybe_remove_italics(config, color)
local style = color.style and 'gui=' .. color.style or 'gui=NONE'
local fg = color.fg and 'guifg = ' .. color.fg or 'guifg = NONE'
local bg = color.bg and 'guibg = ' .. color.bg or 'guibg = NONE'
local sp = color.sp and 'guisp = ' .. color.sp or ''
vim.cmd(
'highlight '
.. group
.. ' '
.. style
.. ' '
.. fg
.. ' '
.. bg
.. ' '
.. sp
)
end
end

M.load_syntax = function(palette)
Expand Down Expand Up @@ -635,6 +654,7 @@ end
local default_config = {
palette = M.classic,
custom_hlgroups = {},
italics = true,
}

M.setup = function(config)
Expand All @@ -650,8 +670,9 @@ M.setup = function(config)
vim.g.colors_name = used_palette.name
local syntax = M.load_syntax(used_palette)
syntax = vim.tbl_deep_extend('keep', config.custom_hlgroups, syntax)
local highlight = highlighter(config)
for group, colors in pairs(syntax) do
M.highlight(group, colors)
highlight(group, colors)
end
local async_load_plugin = nil
async_load_plugin = vim.loop.new_async(vim.schedule_wrap(function()
Expand All @@ -662,7 +683,7 @@ M.setup = function(config)
plugin_syntax
)
for group, colors in pairs(plugin_syntax) do
M.highlight(group, colors)
highlight(group, colors)
end
async_load_plugin:close()
end))
Expand Down