Closed magthe closed 2 months ago
I've thought of that; might be hard to do in a performant manner. How does the user configure enclosing block level types? It doesn't seem to use any treesitter config?
Notes on how to implement:
-highlight
versions of the face for the last highlighted depth with their normal un-highlighted equivalents in the current region-highlight
versions in the (possibly new) region with their -highlight
equivalentsAwkwardly, in addition to the usual (next-single-property-change (point) 'face)
rigamarole, you must also check inside any 'display
strings in the region (tabs, blank lines), and perform the same face-swap operation in any that exist there. If this sounds like so much work you should just throw away the formatting and redo it, you can't really use just font-lock
for this, because that is optimized to update fonts on text changes, whereas this must run in a post-command-hook even after simple movements within the buffer.
Not at all obvious how to do this well. Perhaps you could go line-by-line within the regions, looking directly at the character of interest (at depth
, if the line has that depth) and altering in place, taking care of tabs and blank lines, that is. The font-lock functions would also need to be aware of the current depth and region of interest, so they don't overwrite the work you did. This could get slow if the block regions are large (classes, for example).
I'm pretty sure that something like combobulate could offer a lot of insights into working with tree-sitter grammars for this.
I'm sorry I can't offer anything more detailed.
Anyway, it was just a suggestion. It was rather cool to see it working in Neovim so I thought I'd suggest it. No pressure at all.
No problem, those are mostly notes to myself. Treesitter is not an issue, I can easily get the bounds of the method/function/if-block etc. at point (well, I'll make the user write a list of such block types of interest). It's more a drawing problem with efficiently updating the faces as you move about. I'll leave this open for a while as a tickler, to see if anyone has any ideas.
v0.5 now includes tree-sitter based scope awareness, with full style configuration both in- and out-of-scope. Give a try and let me know of any problems.
A colleague pointed me to indent-blankline for Neovim, and it has a rather cool feature in that it can highlight the current block/scope by using information from treesitter:
There are more examples on the project's GitHub page.
Maybe this is a worthy addition to indent-bars.