andersevenrud / nordic.nvim

A nord-esque colorscheme for neovim
MIT License
174 stars 12 forks source link

Use vim.api.nvim_set_hl() #69

Open gegoune opened 2 years ago

gegoune commented 2 years ago

With https://github.com/neovim/neovim/commit/4aa0cdd3aa117e032325edeb755107acd4ecbf84 merged in it is possible now to use vim.api.nvim_set_hl(0, …) to set highlights for global :highlight namespace.

I have noticed in nordic's code that you are using vim.highlight.create but couldn't find it in documentation. What is it?

andersevenrud commented 2 years ago

This theme uses an internal method:

https://github.com/neovim/neovim/blob/5be2cdd913ce94bf3b88ce70042fbf7a92066459/runtime/lua/vim/highlight.lua#L6-L13

Suppose this ideally should be copied into this repo because it's marked as private, hence no guarantee to keep working in later releases :)

gegoune commented 2 years ago

So it uses vim.cmd, that makes sense. I think I could try to give PR implementing vim.api.nvim_set_hl() a go.

andersevenrud commented 2 years ago

To use the current (i.e. 0.6.1) nvim_set_hl signature you can just do this:

local ns = vim.api.nvim_create_namespace('nordic')
vim.api.nvim_set_hl(ns, ...)

Not really sure if it's worth supporting the 0 argument value until it hits a release, because currently this needs a vim.has() and some condition for backwards compatibility :thinking:

gegoune commented 2 years ago

vim.version().minor >= 7 should work as well.

And I am not sure if using nordic namespace would apply global highlight, would it?

andersevenrud commented 2 years ago

I believe it will work exactly the same. The 0 argument is just a way to eliminate the need to create your own ns.

gegoune commented 2 years ago

Unless I am doing something wrong I am getting different results depending on whether 0 or custom namespace is used. It works with 0 but not with ns.

andersevenrud commented 2 years ago

I see. I'm not familiar with this specific highlighting function, but in hindsight that makes sense... it's the same for virtual text which I've used extensively in another plugin I work on. Derp!

gegoune commented 2 years ago

I am working on some refactor to nordic to work with that new interface. Will get it to working state and open PR.

andersevenrud commented 2 years ago

Since vim.highlight.create now emits a deprecation warning on main neovim branch, I added basic support for the new API.

https://github.com/andersevenrud/nordic.nvim/commit/eb096c03853b8cc24457263c9ceed90256566118