Skip to content

Commit c6553b3

Browse files
author
Jakub Łuczyński
committed
Use lua API function nvim_set_hl
Requires nvim 0.7+ Note (from docs): The fg and bg keys also accept the string values `"fg"` or `"bg"` which act as aliases to the corresponding foreground and background values of the Normal group. If the Normal group has not been defined, using these values results in an error.
1 parent 6fb4f7f commit c6553b3

File tree

2 files changed

+39
-48
lines changed

2 files changed

+39
-48
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Monokai Theme for Neovim with tree-sitter support
1212

1313
## Prerequisites
1414

15-
Neovim >= 0.5.
15+
Neovim >= 0.7.
1616

1717
## Installation
1818
| Plugin Manager | Command |

lua/monokai.lua

Lines changed: 38 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -118,23 +118,12 @@ M.ristretto = {
118118
diff_text = '#23324d',
119119
}
120120

121-
local function remove_italics(config, colors)
122-
if not config.italics and colors.style == 'italic' then
123-
colors.style = nil
124-
end
125-
return colors
126-
end
127-
128121
local function highlighter(config)
129-
return function(group, color)
130-
color = remove_italics(config, color)
131-
local style = color.style and 'gui=' .. color.style or 'gui=NONE'
132-
local fg = color.fg and 'guifg = ' .. color.fg or 'guifg = NONE'
133-
local bg = color.bg and 'guibg = ' .. color.bg or 'guibg = NONE'
134-
local sp = color.sp and 'guisp = ' .. color.sp or ''
135-
vim.cmd(
136-
'highlight ' .. group .. ' ' .. style .. ' ' .. fg .. ' ' .. bg .. ' ' .. sp
137-
)
122+
return function(group, val)
123+
if not config.italics then
124+
val.italic = false
125+
end
126+
vim.api.nvim_set_hl(0, group, val)
138127
end
139128
end
140129

@@ -167,7 +156,7 @@ M.load_syntax = function(palette)
167156
bg = palette.base3,
168157
},
169158
Cursor = {
170-
style = 'reverse',
159+
reverse=true,
171160
},
172161
ColorColumn = {
173162
bg = palette.base3,
@@ -204,19 +193,19 @@ M.load_syntax = function(palette)
204193
},
205194
ModeMsg = {
206195
fg = palette.white,
207-
style = 'bold',
196+
bold = true,
208197
},
209198
MoreMsg = {
210199
fg = palette.white,
211-
style = 'bold',
200+
bold = true,
212201
},
213202
ErrorMsg = {
214203
fg = palette.red,
215-
style = 'bold',
204+
bold = true,
216205
},
217206
WarningMsg = {
218207
fg = palette.yellow,
219-
style = 'bold',
208+
bold = true,
220209
},
221210
VertSplit = {
222211
fg = palette.brown,
@@ -244,26 +233,26 @@ M.load_syntax = function(palette)
244233
},
245234
SpellBad = {
246235
fg = palette.red,
247-
style = 'undercurl',
236+
undercurl = true,
248237
},
249238
SpellCap = {
250239
fg = palette.purple,
251-
style = 'undercurl',
240+
undercurl = true,
252241
},
253242
SpellRare = {
254243
fg = palette.aqua,
255-
style = 'undercurl',
244+
undercurl = true,
256245
},
257246
SpellLocal = {
258247
fg = palette.pink,
259-
style = 'undercurl',
248+
undercurl = true,
260249
},
261250
SpecialKey = {
262251
fg = palette.pink,
263252
},
264253
Title = {
265254
fg = palette.yellow,
266-
style = 'bold',
255+
bold = true,
267256
},
268257
Directory = {
269258
fg = palette.aqua,
@@ -329,7 +318,7 @@ M.load_syntax = function(palette)
329318
},
330319
Function = {
331320
fg = palette.green,
332-
style = 'italic',
321+
italic = true,
333322
},
334323
Statement = {
335324
fg = palette.pink,
@@ -342,7 +331,7 @@ M.load_syntax = function(palette)
342331
},
343332
Keyword = {
344333
fg = palette.pink,
345-
style = 'italic',
334+
italic = true,
346335
},
347336
PreProc = {
348337
fg = palette.green,
@@ -370,7 +359,7 @@ M.load_syntax = function(palette)
370359
},
371360
SpecialComment = {
372361
fg = palette.grey,
373-
style = 'italic',
362+
italic = true,
374363
},
375364
Tag = {
376365
fg = palette.orange,
@@ -380,10 +369,10 @@ M.load_syntax = function(palette)
380369
},
381370
Comment = {
382371
fg = palette.base6,
383-
style = 'italic',
372+
italic = true,
384373
},
385374
Underlined = {
386-
style = 'underline',
375+
underline = true,
387376
},
388377
Ignore = {},
389378
Error = {
@@ -400,16 +389,16 @@ M.load_syntax = function(palette)
400389
fg = palette.grey,
401390
},
402391
vCursor = {
403-
style = 'reverse',
392+
reverse = true,
404393
},
405394
iCursor = {
406-
style = 'reverse',
395+
reverse = true,
407396
},
408397
lCursor = {
409-
style = 'reverse',
398+
reverse = true,
410399
},
411400
CursorIM = {
412-
style = 'reverse',
401+
reverse = true,
413402
},
414403
CursorColumn = {
415404
bg = palette.base3,
@@ -423,7 +412,7 @@ M.load_syntax = function(palette)
423412
},
424413
QuickFixLine = {
425414
fg = palette.purple,
426-
style = 'bold',
415+
bold = true,
427416
},
428417
Debug = {
429418
fg = palette.orange,
@@ -463,7 +452,7 @@ M.load_plugin_syntax = function(palette)
463452
},
464453
TSComment = {
465454
fg = palette.base6,
466-
style = 'italic',
455+
italic = true,
467456
},
468457
TSConstant = {
469458
fg = palette.aqua,
@@ -485,22 +474,22 @@ M.load_plugin_syntax = function(palette)
485474
},
486475
TSFunction = {
487476
fg = palette.green,
488-
style = 'italic',
477+
italic = true,
489478
},
490479
TSFuncBuiltin = {
491480
fg = palette.aqua,
492481
},
493482
TSFuncMacro = {
494483
fg = palette.green,
495-
style = 'italic',
484+
italic = true,
496485
},
497486
TSKeyword = {
498487
fg = palette.pink,
499-
style = 'italic',
488+
italic = true,
500489
},
501490
TSKeywordFunction = {
502491
fg = palette.pink,
503-
style = 'italic',
492+
italic = true,
504493
},
505494
TSKeywordOperator = {
506495
fg = palette.pink,
@@ -599,19 +588,19 @@ M.load_plugin_syntax = function(palette)
599588
fg = palette.aqua,
600589
},
601590
DiagnosticUnderlineError = {
602-
style = 'undercurl',
591+
undercurl=true,
603592
sp = palette.red,
604593
},
605594
DiagnosticUnderlineWarn = {
606-
style = 'undercurl',
595+
undercurl=true,
607596
sp = palette.yellow,
608597
},
609598
DiagnosticUnderlineInfo = {
610-
style = 'undercurl',
599+
undercurl=true,
611600
sp = palette.white,
612601
},
613602
DiagnosticUnderlineHint = {
614-
style = 'undercurl',
603+
undercurl=true,
615604
sp = palette.aqua,
616605
},
617606
CursorWord0 = {
@@ -630,7 +619,6 @@ M.load_plugin_syntax = function(palette)
630619
},
631620
NvimTreeSpecialFile = {
632621
fg = palette.white,
633-
style = 'NONE',
634622
},
635623

636624
-- Telescope
@@ -643,7 +631,7 @@ M.load_plugin_syntax = function(palette)
643631
},
644632
TelescopeSelection = {
645633
fg = palette.white,
646-
style = 'bold',
634+
bold=true,
647635
},
648636
TelescopeSelectionCaret = {
649637
fg = palette.green,
@@ -716,6 +704,9 @@ M.setup = function(config)
716704
local syntax = M.load_syntax(used_palette)
717705
syntax = vim.tbl_deep_extend('keep', config.custom_hlgroups, syntax)
718706
local highlight = highlighter(config)
707+
-- https://github.com/neovim/neovim/issues/20008#issue-1355604714
708+
-- normal must be defined first so that bg/fg can work
709+
highlight('Normal', syntax['Normal'])
719710
for group, colors in pairs(syntax) do
720711
highlight(group, colors)
721712
end

0 commit comments

Comments
 (0)