Tabstospaces - limit length

Alter tabstospaces function and calling code so it truncates at max
length rather than risking error (because replacing a tab with multiple
spaces can increase length).