Highlight all pairs (rainbow)

I’m looking for a plugin that highlights all pairs ({}()[]""'' etc.) with each pair having a different color.
This highlighting could be done on demand, (for example when I’m looking for that one unclosed parenthesis).

I’m not sure if there is already a plugin for this, if not, I might attempt writing one.

Edit: I wrote one: kakoune-rainbow

you mean like rainbow plugins for Vim and Emacs?

Still waiting for something like this:

Yes! Exactly like https://github.com/luochen1990/rainbow

I believe Kakoune handles this usecase by using power of m, <a-i>, and <a-a>, and with plugins like kak-tree you can have selections based on context information from standalone parser (treesitter).

That’s how I currently find missing parens (if I don’t have a linter that shows it), I use m on every opening paren, until I find one without matching closing paren, but I don’t see how I can do this faster (i.e. with one command).
If you have a suggestion, let me know.

Anyway, I think a rainbow-like plugin would make this easier, as a missing paren is more obvious due to the imbalance in colors.

It also would be interesting to see paredit-like commands in Kakoue


There’s already Parinfer implementation by @eraserhd, which should make it easier to handle parens in LISPs

I made the plugin: https://github.com/JJK96/kakoune-rainbow

You can accomplish this by setting the rainbow_faces to faces that highlight the background. And setting the rainbow_highlight_background option to true.

1 Like

omg :astonished:

I’ve tested it on my emacs init.el (1354 LOC, 2456 parens in total) and it is pretty slow as of now. Maybe it should run in background?

Although I appreciate that you’ve added ability to color a background, and it is a nice feature, this is not really the same. It’s hard to understand it from static image (and I should have explained that better), but the highlighting on that screenshot is actually dynamic. It adds more and more colors depending on how deep your cursor is inside the syntax tree. So it is more like a dynamic indentation guides for Lisp.

Right, that’s a lot less trivial to implement.

Nice and very useful yet. The one annoyance I see is that it mess with my / registry.

I guess that -draft on a recursive eval won’t work, that’s why you did not add one. We need some kind of -recursive-draft option on eval. The context would be created and destroyed only on the first evaluation of the given evaluate-commands in the stack. I’m not even sure that the concept of stack exists in kak scripts :grin:. @mawww could tell.

I think recursive draft does work, I did not add a draft context there since it should not be needed because that function should only be called from the rainbow function, which calls it inside a draft context.

Edit: I pushed a fix to save the ‘/’ register, I thought this was saved automatically (like for execute-keys) but according to the docs this is not the case.

Nice. Thank you.