mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-01 23:20:26 +02:00
Jedi Code Format: Remove blank lines before type, const, var, begin tokens inside a procedure/function. Issue #39990, patch by Domingo Galmés.
This commit is contained in:
parent
2d95dc76d7
commit
f112427168
@ -46,7 +46,7 @@ implementation
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
JcfSettings, FormatFlags, Tokens, TokenUtils,
|
JcfSettings, FormatFlags, Tokens, TokenUtils,
|
||||||
ParseTreeNodeType;
|
ParseTreeNodeType, ParseTreeNode;
|
||||||
|
|
||||||
function IsPlaceForBlankLineRemoval(const ptToken, ptNextSolidToken:
|
function IsPlaceForBlankLineRemoval(const ptToken, ptNextSolidToken:
|
||||||
TSourceToken): boolean;
|
TSourceToken): boolean;
|
||||||
@ -90,6 +90,8 @@ var
|
|||||||
lcNext, lcTest: TSourceToken;
|
lcNext, lcTest: TSourceToken;
|
||||||
liReturnCount: integer;
|
liReturnCount: integer;
|
||||||
liMaxReturns: integer;
|
liMaxReturns: integer;
|
||||||
|
lcBlock: TParseTreeNode;
|
||||||
|
lcDeclSection: TParseTreeNode;
|
||||||
begin
|
begin
|
||||||
Result := False;
|
Result := False;
|
||||||
lcSourceToken := TSourceToken(pcNode);
|
lcSourceToken := TSourceToken(pcNode);
|
||||||
@ -102,6 +104,8 @@ begin
|
|||||||
exit;
|
exit;
|
||||||
|
|
||||||
lcNext := lcSourceToken.NextTokenWithExclusions([ttWhiteSpace, ttReturn]);
|
lcNext := lcSourceToken.NextTokenWithExclusions([ttWhiteSpace, ttReturn]);
|
||||||
|
if lcNext=nil then
|
||||||
|
exit;
|
||||||
|
|
||||||
{ it must be a 'var', 'const', 'type' or 'begin'
|
{ it must be a 'var', 'const', 'type' or 'begin'
|
||||||
in the procedure defs/body section }
|
in the procedure defs/body section }
|
||||||
@ -115,6 +119,27 @@ begin
|
|||||||
liMaxReturns := FormattingSettings.Returns.MaxBlankLinesInSection + 1;
|
liMaxReturns := FormattingSettings.Returns.MaxBlankLinesInSection + 1;
|
||||||
lcTest := lcSourceToken;
|
lcTest := lcSourceToken;
|
||||||
|
|
||||||
|
// function fooo;
|
||||||
|
// --> no blank lines beetwen function/procedure declaration and sections.
|
||||||
|
// var, const, type, begin.
|
||||||
|
|
||||||
|
// find nBlock, can be grandfader or great-grandfather of node
|
||||||
|
lcDeclSection:=nil;
|
||||||
|
lcDeclSection:=lcNext.Parent;
|
||||||
|
if (lcDeclSection<>nil) and not (lcDeclSection.NodeType in [nDeclSection,nCompoundStatement]) then
|
||||||
|
lcDeclSection:=lcDeclSection.Parent;
|
||||||
|
if (lcDeclSection<>nil) and not (lcDeclSection.NodeType in [nDeclSection,nCompoundStatement]) then
|
||||||
|
lcDeclSection:=lcDeclSection.Parent;
|
||||||
|
if lcDeclSection<>nil then
|
||||||
|
begin
|
||||||
|
lcBlock:=lcDeclSection.Parent;
|
||||||
|
if (lcBlock<>nil) and (lcBlock.NodeType=nBlock) then
|
||||||
|
begin
|
||||||
|
//if lcBlock.IndexOfChild(lcDeclSection)=0 then //Only the first section of nBlock
|
||||||
|
liMaxREturns:=1;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
{ remove all returns up to that point (except one) }
|
{ remove all returns up to that point (except one) }
|
||||||
while (lcTest <> lcNext) do
|
while (lcTest <> lcNext) do
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user