From 6b1e474e2b6320c6e61ae796b2b6e667a8dc1ced Mon Sep 17 00:00:00 2001 From: DomingoGP Date: Sun, 1 Oct 2023 21:21:02 +0200 Subject: [PATCH] Jedi code format: dont't ident comments before procedures at the end of sections. Issue #40533. (cherry picked from commit 8035014eaffe30c2b71c9c49d4f76b3405b84590) --- components/jcf2/Process/Indent/Indenter.pas | 25 +++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/components/jcf2/Process/Indent/Indenter.pas b/components/jcf2/Process/Indent/Indenter.pas index f3e35aae83..e723c4d86b 100644 --- a/components/jcf2/Process/Indent/Indenter.pas +++ b/components/jcf2/Process/Indent/Indenter.pas @@ -128,6 +128,16 @@ begin Result := True; end; +function HasEmptyLineAfterComment(const pt: TSourceToken): Boolean; +var + pnext: TSourceToken; +begin + result:=false; + pnext:=pt.NextTokenWithExclusions([ttWhiteSpace]); //End of current line + if (pnext<>nil) and (pnext.TokenType=ttReturn) then + result:= pnext.NextTokenTypeWithExclusions([ttWhiteSpace])=ttReturn; +end; + function IsIndented(const pt: TSourceToken): Boolean; begin Result := IsFirstSolidTokenOnLine(pt); @@ -669,6 +679,21 @@ begin end; end; + // last comments in var, const,... sections belongs to the next procedure/function. + if (pt.TokenType=ttComment) and pt.HasParentNode([nTypeSection,nVarSection,nConstSection,nUses]) + and (pt.NextSolidTokenType in ProcedureWords) + and ( not pt.HasParentNode(ObjectBodies + [nRecordType])) + //not followed by a blank line. + and not HasEmptyLineAfterComment(pt) then + begin + Result:=0; + if FormattingSettings.Indent.IndentLibraryProcs then + begin + if pt.HasParentNode([nLibrary, nProgram]) and (liIndentCount >= 1) then + Result:=1; + end; + end; + end; constructor TIndenter.Create;