I came from jEdit which has folding. I have one report that uses folding that I still have to run in jEdit. I’m now so entrenched in Kakoune that jEdit is painful to run so I finally hacked some code to implement rudimentary “folding” in Kakoune. The jEdit folding was static in that it only folded and unfolded lines without modifying the underlying folded lines. The folded lines index the non-folded portion of the file and I had written jEdit macros to jump from the index to the non-folded portion of the file.
To simulate this in Kakoune I created a scratch buffer and wrote a number of short awk scripts to populate the scratch buffer with the initial fully folded view and to get additional lines where I want to drill down. The awk scripts directly read the report file not a Kakoune buffer. I ended up modifying the underlying report to add line numbers into the text of the file to be folded to link lines in the scratch buffer with the underlying file. It’s not a slick as jEdit, but it should get me off jEdit. Kakoune is so programmable I expect to be able to eventually improve the solution beyond jEdit.
This triggered some more generic thoughts on the Kakoune folding problem. I used a scratch buffer for folding, I didn’t attempt to do it in the buffer for the report file itself. How about a new type of buffer in Kakoune explicitly designed to support folding? The folding buffer would be linked to a normal file buffer. The user would write a script to populate the folding buffer with a subset of the lines in the underlying file buffer, but Kakoune would retain the line numbers of the underlying file buffer without having to hack line numbers into the file contents. Also it would be nice if Kakoune could automatically track the folded lines. It would be nice if Kakoune would reflect edits in the folded buffer back into the file buffer. I think it could be done vice versa as well. I admit that inserting a new line in the folded buffer might be difficult to define - i.e. where exactly does one insert a new line in or beside other folded lines. Folded (hidden) lines - would simply not be present in the folded buffer unless explicitly pulled in and not subject to change through global selection.
As best I understand Mawww’s main issue with folding is the tight coupling between the buffer and the file. Just maybe an additional type of buffer will break through this barrier or at least trigger some thoughts to enable folding. This could be implemented in stages. I.e. starting with no updates/synchronization either direction between the folding buffer and underlying file buffers, adding synchronization from the folding to the file buffer etc.