diff --git a/components/codetools/keywordfunclists.pas b/components/codetools/keywordfunclists.pas index ef8f683b74..3bc8f87c53 100644 --- a/components/codetools/keywordfunclists.pas +++ b/components/codetools/keywordfunclists.pas @@ -161,19 +161,19 @@ var : TKeyWordFunctionList; UpChars: array[char] of char; - IsSpaceChar, // [#0..#32] - IsLineEndChar, - IsWordChar, // ['a'..'z','A'..'Z'] - IsNonWordChar, // [#0..#127]-IsIdentChar - IsIdentStartChar, - IsIdentChar, - IsDottedIdentChar, - IsNumberChar, + IsSpaceChar, // [#0..#32] + IsLineEndChar, // [#10,#13] + IsWordChar, // ['a'..'z','A'..'Z'] + IsNonWordChar, // [#0..#127]-IsIdentChar + IsIdentStartChar, // ['a'..'z','A'..'Z','_'] + IsIdentChar, // ['a'..'z','A'..'Z','_','0'..'9'] + IsDottedIdentChar, // ['.','a'..'z','A'..'Z','_','0'..'9'] + IsNumberChar, // ['0'..'9'] IsCommentStartChar, IsCommentEndChar, - IsHexNumberChar, - IsEqualOperatorStartChar, - IsAfterFloatPointChar: + IsHexNumberChar, // ['0'..'9','a'..'f','A'..'F'] + IsEqualOperatorStartChar, // [':','+','-','/','*','<','>'] + IsAfterFloatPointChar: // ['0'..'9','e','E'] array[char] of boolean; function UpperCaseStr(const s: string): string; diff --git a/components/codetools/sourcechanger.pas b/components/codetools/sourcechanger.pas index d928be2da5..6dc8b61bd5 100644 --- a/components/codetools/sourcechanger.pas +++ b/components/codetools/sourcechanger.pas @@ -1634,6 +1634,8 @@ var OldIndent: Integer; OldAtomStart: LongInt; AfterProcedure: Boolean; + CurDoNotInsertSpaceAfter: TAtomTypes; + CurDoNotInsertSpaceInFront: TAtomTypes; begin //DebugLn('**********************************************************'); //DebugLn('[TBeautifyCodeOptions.BeautifyStatement] "',AStatement,'"'); @@ -1641,6 +1643,8 @@ begin // set flags CurFlags:=BeautifyFlags; OldIndent:=Indent; + CurDoNotInsertSpaceAfter:=DoNotInsertSpaceAfter+[atNewLine,atSpace]; + CurDoNotInsertSpaceInFront:=DoNotInsertSpaceInFront+[atNewLine,atSpace]; try if bcfNoIndentOnBreakLine in CurFlags then Indent:=0; @@ -1696,10 +1700,10 @@ begin and (SameText(CurAtom, 'procedure') or SameText(CurAtom, 'function')) then AfterProcedure := True; - //DebugLn(['TBeautifyCodeOptions.BeautifyStatement ',CurAtom,' LastAtomType=',AtomTypeNames[LastAtomType],',',LastAtomType in DoNotInsertSpaceAfter,',',LastAtomType in DoInsertSpaceAfter,' CurAtomType=',AtomTypeNames[CurAtomType],',',CurAtomType in DoNotInsertSpaceInFront,',',CurAtomType in DoInsertSpaceInFront]); - if ((Result='') or (Result[length(Result)]<>' ')) - and (not (CurAtomType in DoNotInsertSpaceInFront)) - and (not (LastAtomType in DoNotInsertSpaceAfter)) + //DebugLn(['TBeautifyCodeOptions.BeautifyStatement ',CurAtom,' LastAtomType=',AtomTypeNames[LastAtomType],',',LastAtomType in CurDoNotInsertSpaceAfter,',',LastAtomType in DoInsertSpaceAfter,' CurAtomType=',AtomTypeNames[CurAtomType],',',CurAtomType in CurDoNotInsertSpaceInFront,',',CurAtomType in DoInsertSpaceInFront]); + if ((Result='') or (not IsSpaceChar[Result[length(Result)]])) + and (not (CurAtomType in CurDoNotInsertSpaceInFront)) + and (not (LastAtomType in CurDoNotInsertSpaceAfter)) and ((CurAtomType in DoInsertSpaceInFront) or (LastAtomType in DoInsertSpaceAfter)) then begin