Use nvim_set_hl()
to set highlights
#280
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.