This is as about the problem D73045 tried to solve,
but I suggest a completely different approach.
What if we just do a post processing for the output?
I.e. first output it to a string and then using our knowledge
about YAML grammar will reformat indentations.
It separates the formatting pass from the original pass,
what makes the whole approach isolated and simple.