Use std::transform instead of custom code
Inserting newline at start of line with foldings would misbehave

Here misbehave means unfolding the folded text on a single line.

Fixes #933
Deleting trailing newline for line with foldings would misbehave

Here misbehave means unfold the folded text (on the same line) but as a single line.

Fixes #257
Use std::function instead of templated argument
Use a capturing lambda function instead of global variable

The code involved is only for debug output.
Add some debug output to layout_t
Update some use of the iterate macro to for(… : …)