quchen / prettyprinter

A modern, extensible and well-documented prettyprinter.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support using tabs instead of spaces for indentation

hololeap opened this issue · comments

I'm looking at using prettyprinter to generate .ebuild files, which use tabs instead of spaces for indentation. Every indentation-related function (such as align and hang) makes use of spaces exclusively with no way to change this behavior. It doesn't look like creating a new rendering function will solve this problem either. The only thing I have thought of would be to add a new field to LayoutOptions which carries the desired indentation character.

Is there a way to use tabs instead of spaces currently? If this is outside the scope of the package, are there any other packages that provide the ease-of-use of prettyprinter (esp. the align and hang functions) but support using tabs for indentation?

The lib is unfortunately a poor fit for tab-indented output, since the WL algorithm keeps track of the current column in lots of places, e.g. the current column variable cc (Current column, i.e. "where the cursor is"). I don’t think this is easy to adapt to tab-based indentation without adding a lot of complexity everywhere that has spaces (leading or not).

A workaround would be postprocessing the output and replacing every 8 leading spaces with a tab.

A workaround would be postprocessing the output and replacing every 8 leading spaces with a tab.

Ok, this is what I ended up doing. I was just curious if this could be a realistic feature. Thanks for responding!