HiPhish / rainbow-delimiters.nvim

Rainbow delimiters for Neovim with Tree-sitter
https://gitlab.com/HiPhish/rainbow-delimiters.nvim
Apache License 2.0
533 stars 39 forks source link

API to toggle rainbow #27

Closed mystilleef closed 1 year ago

mystilleef commented 1 year ago

Neovim version

master

Language affected

No response

Query

No response

Strategy

No response

Description

Can you provide an API to explicitly toggle Rainbow? I like to disable colors in insert mode.
HiPhish commented 1 year ago

What would you want this API to be like? Since you want to disable and enable it when changing modes how about three functions like this?

-- Disable rainbow for buffer (bufnr or 0 for current buffer)
rainbow_delimiters.disable(buffnr)

-- Enable rainbow again for buffer (bufnr or 0 for current buffer)
rainbow_delimiters.enable(buffnr)

-- Toggle rainbow for buffer (bufnr or 0 for current buffer)
rainbow_delimiters.enable(buffnr)

You could then call these functions in an autocommand for InsertEnter and InsertLeave.

mystilleef commented 1 year ago

Yes, those APIs are perfect.

mystilleef commented 1 year ago
-- Toggle rainbow for buffer (bufnr or 0 for current buffer)
rainbow_delimiters.enable(buffnr)

I assume you meant to write rainbow_delimiters.toggle(bufnr) and not enable. enable should not toggle to avoid confusion.

HiPhish commented 1 year ago

Try out the current master; the functions are implemented now. And yes, that was a typo, I meant of toggle of course.

mystilleef commented 1 year ago

Great work!

There's only 1 issue. Passing nothing to the APIs should automatically use the current buffer.

As it stands you're forced to pass a buffer number to the APIs which shouldn't be necessary. Public APIs in general should be nil friendly.

Other than that after my 10 minutes of testing, it seems to work well.

Thank you!

HiPhish commented 1 year ago

I have made them nil-tolerant now. I don't think that is a general think across Neovim functions, but on the other hand it barely adds any code, so went through with it anyway.