I'd like to write a plugin that automatically sets the foldlevel
of a newly opened document so that as much of the document fits on the screen as possible. (In other words, I'd like to make sure short documents open fully expanded while long documents open mostly collapsed.)
Is there any built-in function in vim that reports the number of visible lines in a document, given the current fold state or a particular fold level? (I.e., closed folds count as one line, but lines you'd have to scroll down to see are counted, too.)