From 0f80c083559265a99c24d1f7833fb4fafb0a84ab Mon Sep 17 00:00:00 2001 From: Geoff McLane Date: Sun, 1 Feb 2015 14:27:02 +0100 Subject: [PATCH] Issue #133 - ever increasing indent! This is a simple but profound change in pprint.c. Since leading space is preserved on script code, after tidy indents the code once, a second run on that tidied file would add more indent to already indented code. This fix should be carefully checked, and removed if there are other bad consequences. Bump the version point to 4 for this change. --- src/pprint.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/pprint.c b/src/pprint.c index 3ce82df..6568c11 100644 --- a/src/pprint.c +++ b/src/pprint.c @@ -652,19 +652,27 @@ static void PFlushLineImpl( TidyDocImpl* doc ) { TidyPrintImpl* pprint = &doc->pprint; - uint i; + uint i, j; CheckWrapLine( doc ); + j = 0; /* Issue #133 - start text output */ if ( WantIndent(doc) ) { uint spaces = GetSpaces( pprint ); - for ( i = 0; i < spaces; ++i ) + for ( i = 0; i < spaces; ++i ) { TY_(WriteChar)( ' ', doc->docOut ); + if (( j < pprint->linelen ) && ( pprint->linebuf[j] == ' ' )) { + /*\ Issue #133 - ever increasing indent on each tidy run + * Now removed any leading spaces by the amount of the indent + \*/ + j++; + } + } } - for ( i = 0; i < pprint->linelen; ++i ) - TY_(WriteChar)( pprint->linebuf[i], doc->docOut ); + for ( ; j < pprint->linelen; j++ ) + TY_(WriteChar)( pprint->linebuf[j], doc->docOut ); if ( IsInString(pprint) ) TY_(WriteChar)( '\\', doc->docOut );