copying implementation of indent() code from miyagawa