vim-restructuredtext icon indicating copy to clipboard operation
vim-restructuredtext copied to clipboard

Maybe not fold the only top-level section

Open buzden opened this issue 7 years ago • 3 comments

If a document has a single top-level section (e.g., a title of a document), it seems, it's better to not to fold it because the first thing you do in this case is unfolding this the only section each time.

buzden avatar Nov 09 '18 10:11 buzden

Agreed, I'd even go so far to suggest that the folding be disabled on default, if that is an option. (Admittedly this can be done at the vim level with set nofoldenable)

@anntzer is it possible to control the folding somehow?

marshallward avatar Nov 09 '18 10:11 marshallward

Seems like a reasonable request. Don't have the time to write a patch now, but I think this needs to be done in a postprocessing step in s:CacheRstFold() (because you need to parse the full document before knowing whether the toplevel section is the only one at its level or not. Just before setting

let b:RstFoldCache = closure.levels

I guess you can check whether closure.levels[1] == 1 (i.e. there's a first-line fold), and then whether there's any other line with levels == 1 (i.e. there's no other section at that level); if so, then decrease all values in closure.levels by 1. (Or keep a counter in Process() to check whether you hit levels == 1 multiple times, etc.)

anntzer avatar Nov 09 '18 11:11 anntzer