An even simpler hack for level-dependent fold highlights?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

An even simpler hack for level-dependent fold highlights?

Herbert Sitz
Noel Henson wrote:
> done a good job though I think it could use a bit of refinement. Perhaps,
> as a group, we could refine it to vim's standards for patches and get it
> included in the next release of vim. Bram has a very good system for
> voting
> for feature inclusion in vim releases. Perhaps it is time for us VO users
> to contribute to a project that has provided us such a great
> platform over the years.
> Noel

Noel (and anyone else interested) -- I wanted to check with you about an alternative solution to showing folded level highlighting that's even cleaner.  I've got it almost but not quite right.

The solution I'm thinking of would involve combining the fold flag attribute with other syntax highlighting attributes.  The original Vim code simply assigns the HLF_FL attribute and doesn't bother to combine it with existing attributes.  "Combining" the attributes would provide a simple solution, so that if you assign a transparent highlight to the foreground of the 'Folded' group in Vim (i.e, the group that uses HLF-FL) then the folded text will have foreground of whatever syntax element is underneath it.  By itself this wouldn't be great, since you also want a way to make the fold standout, but you can specify that the fold be bold, italic, underlined or something else.

This attribute combining solution, if we can get it to work, requires changing only one line of the original Vim source (the previous hack adding new FoldLevel highlight flags is completely unnecessary).  I've made the change, but each of my highlighted folds is now showing the highlight of  the line one above it, not of the underlying line itself.  It's some kind of problem in specifying the offset, but I can't figure out exactly what.  Here's the line of code I changed:

**** around line 2200 in screen.c
    /* Set all attributes of the 'number' column and the text */
******original line
    /*RL_MEMSET(col, hl_attr(foldlevelflag), W_WIDTH(wp) - col);*/
******* revised line that highlights fold with colors of outline line one above
    RL_MEMSET(col, hl_combine_attr( ScreenAttrs[off + col ],
                                         W_WIDTH(wp) - col);

I don't know much C at all.   RL_MEMSET appears to be a macro that's defined right above it in the source.  I've tried a few different combinations to change the offset for ScreenAttrs[] in the hl_combine_attr function to try to get it to work, but so far haven't figured out the magic change.

Along with that change in the original source, you need only to add this line to your color or syntax file:

hi Folded gui=bold guifg=NONE guibg=bg

The color 'NONE' is actually transparent and allows highlight of any element in line underneath to show through.  That was pretty much useless with original code because it always showed through to default highlight, but with the combined_attr change, it will reveal highlight of whatever element is underneath.  (Only problem right now is it's "revealing" the highlight of the line one line above.)

I thought you might be curious about this possible solution, and you may also be better able to track down what offset specification is going to actually work.  If you do take a look at it I'd like to hear any ideas or solutions you find.

-- Herb