marshallward / vim-restructuredtext

Syntax file for reStructuredText on Vim.
26 stars 12 forks source link

Maybe not fold the only top-level section #35

Open buzden opened 5 years ago

buzden commented 5 years ago

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.

marshallward commented 5 years ago

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?

anntzer commented 5 years ago

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.)