Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use lua API function nvim_set_hl #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Monokai Theme for Neovim with tree-sitter support

## Prerequisites

Neovim >= 0.5.
Neovim >= 0.7.

## Installation
| Plugin Manager | Command |
Expand Down
85 changes: 38 additions & 47 deletions lua/monokai.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,12 @@ M.ristretto = {
diff_text = '#23324d',
}

local function 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 = 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
)
return function(group, val)
if not config.italics then
val.italic = false
end
vim.api.nvim_set_hl(0, group, val)
end
end

Expand Down Expand Up @@ -167,7 +156,7 @@ M.load_syntax = function(palette)
bg = palette.base3,
},
Cursor = {
style = 'reverse',
reverse=true,
},
ColorColumn = {
bg = palette.base3,
Expand Down Expand Up @@ -204,19 +193,19 @@ M.load_syntax = function(palette)
},
ModeMsg = {
fg = palette.white,
style = 'bold',
bold = true,
},
MoreMsg = {
fg = palette.white,
style = 'bold',
bold = true,
},
ErrorMsg = {
fg = palette.red,
style = 'bold',
bold = true,
},
WarningMsg = {
fg = palette.yellow,
style = 'bold',
bold = true,
},
VertSplit = {
fg = palette.brown,
Expand Down Expand Up @@ -244,26 +233,26 @@ M.load_syntax = function(palette)
},
SpellBad = {
fg = palette.red,
style = 'undercurl',
undercurl = true,
},
SpellCap = {
fg = palette.purple,
style = 'undercurl',
undercurl = true,
},
SpellRare = {
fg = palette.aqua,
style = 'undercurl',
undercurl = true,
},
SpellLocal = {
fg = palette.pink,
style = 'undercurl',
undercurl = true,
},
SpecialKey = {
fg = palette.pink,
},
Title = {
fg = palette.yellow,
style = 'bold',
bold = true,
},
Directory = {
fg = palette.aqua,
Expand Down Expand Up @@ -329,7 +318,7 @@ M.load_syntax = function(palette)
},
Function = {
fg = palette.green,
style = 'italic',
italic = true,
},
Statement = {
fg = palette.pink,
Expand All @@ -342,7 +331,7 @@ M.load_syntax = function(palette)
},
Keyword = {
fg = palette.pink,
style = 'italic',
italic = true,
},
PreProc = {
fg = palette.green,
Expand Down Expand Up @@ -370,7 +359,7 @@ M.load_syntax = function(palette)
},
SpecialComment = {
fg = palette.grey,
style = 'italic',
italic = true,
},
Tag = {
fg = palette.orange,
Expand All @@ -380,10 +369,10 @@ M.load_syntax = function(palette)
},
Comment = {
fg = palette.base6,
style = 'italic',
italic = true,
},
Underlined = {
style = 'underline',
underline = true,
},
Ignore = {},
Error = {
Expand All @@ -400,16 +389,16 @@ M.load_syntax = function(palette)
fg = palette.grey,
},
vCursor = {
style = 'reverse',
reverse = true,
},
iCursor = {
style = 'reverse',
reverse = true,
},
lCursor = {
style = 'reverse',
reverse = true,
},
CursorIM = {
style = 'reverse',
reverse = true,
},
CursorColumn = {
bg = palette.base3,
Expand All @@ -423,7 +412,7 @@ M.load_syntax = function(palette)
},
QuickFixLine = {
fg = palette.purple,
style = 'bold',
bold = true,
},
Debug = {
fg = palette.orange,
Expand Down Expand Up @@ -463,7 +452,7 @@ M.load_plugin_syntax = function(palette)
},
TSComment = {
fg = palette.base6,
style = 'italic',
italic = true,
},
TSConstant = {
fg = palette.aqua,
Expand All @@ -485,22 +474,22 @@ M.load_plugin_syntax = function(palette)
},
TSFunction = {
fg = palette.green,
style = 'italic',
italic = true,
},
TSFuncBuiltin = {
fg = palette.aqua,
},
TSFuncMacro = {
fg = palette.green,
style = 'italic',
italic = true,
},
TSKeyword = {
fg = palette.pink,
style = 'italic',
italic = true,
},
TSKeywordFunction = {
fg = palette.pink,
style = 'italic',
italic = true,
},
TSKeywordOperator = {
fg = palette.pink,
Expand Down Expand Up @@ -599,19 +588,19 @@ M.load_plugin_syntax = function(palette)
fg = palette.aqua,
},
DiagnosticUnderlineError = {
style = 'undercurl',
undercurl=true,
sp = palette.red,
},
DiagnosticUnderlineWarn = {
style = 'undercurl',
undercurl=true,
sp = palette.yellow,
},
DiagnosticUnderlineInfo = {
style = 'undercurl',
undercurl=true,
sp = palette.white,
},
DiagnosticUnderlineHint = {
style = 'undercurl',
undercurl=true,
sp = palette.aqua,
},
CursorWord0 = {
Expand All @@ -630,7 +619,6 @@ M.load_plugin_syntax = function(palette)
},
NvimTreeSpecialFile = {
fg = palette.white,
style = 'NONE',
},

-- Telescope
Expand All @@ -643,7 +631,7 @@ M.load_plugin_syntax = function(palette)
},
TelescopeSelection = {
fg = palette.white,
style = 'bold',
bold=true,
},
TelescopeSelectionCaret = {
fg = palette.green,
Expand Down Expand Up @@ -716,6 +704,9 @@ M.setup = function(config)
local syntax = M.load_syntax(used_palette)
syntax = vim.tbl_deep_extend('keep', config.custom_hlgroups, syntax)
local highlight = highlighter(config)
-- https://github.com/neovim/neovim/issues/20008#issue-1355604714
-- normal must be defined first so that bg/fg can work
highlight('Normal', syntax['Normal'])
for group, colors in pairs(syntax) do
highlight(group, colors)
end
Expand Down