Currently, it's not possible to set certain highlight attributes for Sniprun's highlight groups. This is because the code is manually constructing VimScript commands, which it then wraps in calls to vim.cmd(), and it only considers a few attributes.
This PR updates the code to use Neovim's nvim_set_hl() API function, which handles all attributes.
Backward compatibility
This update should be mostly backward compatible with the previous way of setting highlights; however, there are some differences to be aware of.
The VimScript :highlight command updates the highlight group if already set, whereas nvim_set_hl() completely replaces the definition.
The VimScript :highlight command accepts an altfont attribute for GUIs, and nvim_set_hl() does not.
See below for documentation on the attributes/options accepted by these two commands.
VimScript :highlight attributes
attr-list is a comma-separated list (without spaces) of the
following items (in any order):
bold
underline
undercurl curly underline
underdouble double underline
underdotted dotted underline
underdashed dashed underline
strikethrough
reverse
inverse same as reverse
italic
standout
altfont
nocombine override attributes instead of combining them
NONE no attributes used (used to reset it)
Lua nvim_set_hl() options
Highlight definition map, accepts the following keys:
• fg (or foreground): color name or "#RRGGBB", see note.
• bg (or background): color name or "#RRGGBB", see note.
• sp (or special): color name or "#RRGGBB"
• blend: integer between 0 and 100
• bold: boolean
• standout: boolean
• underline: boolean
• undercurl: boolean
• underdouble: boolean
• underdotted: boolean
• underdashed: boolean
• strikethrough: boolean
• italic: boolean
• reverse: boolean
• nocombine: boolean
• link: name of another highlight group to link to, see
|:hi-link|.
• default: Don't override existing definition |:hi-default|
• ctermfg: Sets foreground of cterm color |ctermfg|
• ctermbg: Sets background of cterm color |ctermbg|
• cterm: cterm attribute map, like |highlight-args|. If not
set, cterm attributes will match those from the attribute
map documented above.
Notes
I removed the autocommand that sets the highlights on the ColorScheme event, since it appears to be unnecessary. The author of the previous highlighting code said they were experiencing issues where some colorschemes clear the highlight groups, causing the defaults to be lost (see here), but I tested this with multiple colorschemes and did not experience this issue myself.
As mentioned here, Sniprun's author wants the highlight groups to be defined in this order of priority:
Description
This PR is related to #278.
Currently, it's not possible to set certain highlight attributes for Sniprun's highlight groups. This is because the code is manually constructing VimScript commands, which it then wraps in calls to
vim.cmd()
, and it only considers a few attributes.This PR updates the code to use Neovim's
nvim_set_hl()
API function, which handles all attributes.Backward compatibility
This update should be mostly backward compatible with the previous way of setting highlights; however, there are some differences to be aware of.
:highlight
command updates the highlight group if already set, whereasnvim_set_hl()
completely replaces the definition.:highlight
command accepts analtfont
attribute for GUIs, andnvim_set_hl()
does not.See below for documentation on the attributes/options accepted by these two commands.
VimScript
:highlight
attributesLua
nvim_set_hl()
optionsNotes
I removed the autocommand that sets the highlights on the
ColorScheme
event, since it appears to be unnecessary. The author of the previous highlighting code said they were experiencing issues where some colorschemes clear the highlight groups, causing the defaults to be lost (see here), but I tested this with multiple colorschemes and did not experience this issue myself.As mentioned here, Sniprun's author wants the highlight groups to be defined in this order of priority:
This PR maintains this priority.