+1 (and view.folded_regions([regions]))
In the meantime you can use view.unfold(sublime.Region(0, view.size())), though that will of course nuke ALL the folds.
So the trick is to just unfold everything and refold the areas you care about.
So if you wanted to unfold comment regions, you’d store the existing regions returned by view.unfold, subtract the comments somehow, then refold.
There’s no builtin RegionSet functionality like subtract available apart from view.sel() so you can either rewrite RegionSet in Python or temporarily set view.sel() to the result of view.unfold to perform calculations.
I think if any region passed to view.unfold intersects a folded region, the entire region will be unfolded, rather than it being subtractive.
Most likely you’d only want to remove an existing folded region if it was of exactly the same size as a comment region. You wouldn’t want to show just the comment of a folded out function yeah? Likewise you wouldn’t want to unfold a whole function when unfolding comments. So the semantics of view.sel().subtract and view.unfold respectively aren’t likely what you are looking for.
Unfortunately the __hash__
function on sublime.Region seems to return the same hash for different regions:
[code]>>> hash(sublime.Region(0, 0))
101618048
hash(sublime.Region(10, 20))
101618048[/code]
If I’m not mistaken, if this wasn’t the case you could just make a set() of regions from the view.unfold list and then subtract the comment region set() relatively efficiently.