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 vim.api.nvim_set_hl() #69

Open
gegoune opened this issue Feb 1, 2022 · 9 comments
Open

Use vim.api.nvim_set_hl() #69

gegoune opened this issue Feb 1, 2022 · 9 comments

Comments

@gegoune
Copy link
Contributor

gegoune commented Feb 1, 2022

With neovim/neovim@4aa0cdd 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
Copy link
Owner

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
Copy link
Contributor Author

gegoune commented Feb 1, 2022

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
Copy link
Owner

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 🤔

@gegoune
Copy link
Contributor Author

gegoune commented Feb 1, 2022

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

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

@andersevenrud
Copy link
Owner

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
Copy link
Contributor Author

gegoune commented Feb 1, 2022

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
Copy link
Owner

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
Copy link
Contributor Author

gegoune commented Feb 1, 2022

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

@andersevenrud
Copy link
Owner

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

eb096c0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants