mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-12 13:50:06 +02:00
codetools: auto indenter: insert procedure
git-svn-id: trunk@26456 -
This commit is contained in:
parent
14c0ca0b26
commit
1970e9cd23
@ -350,7 +350,7 @@ type
|
|||||||
function FindPolicyInExamples(StartCode: TCodeBuffer;
|
function FindPolicyInExamples(StartCode: TCodeBuffer;
|
||||||
Typ, SubTyp: TFABBlockType): TFABPolicies;
|
Typ, SubTyp: TFABBlockType): TFABPolicies;
|
||||||
function GetNestedCommentsForCode(Code: TCodeBuffer): boolean;
|
function GetNestedCommentsForCode(Code: TCodeBuffer): boolean;
|
||||||
function FindStackPosForBlockCloseAtPos(const Source: string;
|
function AdjustByNextAtom(const Source: string;
|
||||||
CleanPos: integer; NestedComments: boolean;
|
CleanPos: integer; NestedComments: boolean;
|
||||||
Stack: TFABBlockStack;
|
Stack: TFABBlockStack;
|
||||||
out TopType: TFABBlockType;
|
out TopType: TFABBlockType;
|
||||||
@ -1252,7 +1252,7 @@ begin
|
|||||||
OnGetNestedComments(Self,Code,Result);
|
OnGetNestedComments(Self,Code,Result);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TFullyAutomaticBeautifier.FindStackPosForBlockCloseAtPos(
|
function TFullyAutomaticBeautifier.AdjustByNextAtom(
|
||||||
const Source: string; CleanPos: integer; NestedComments: boolean;
|
const Source: string; CleanPos: integer; NestedComments: boolean;
|
||||||
Stack: TFABBlockStack; out TopType: TFABBlockType; out TopTypeValid: boolean
|
Stack: TFABBlockStack; out TopType: TFABBlockType; out TopTypeValid: boolean
|
||||||
): integer;
|
): integer;
|
||||||
@ -1270,7 +1270,7 @@ function TFullyAutomaticBeautifier.FindStackPosForBlockCloseAtPos(
|
|||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
i:=FindStackPosForBlockCloseAtPos;
|
i:=AdjustByNextAtom;
|
||||||
if (i>=0) and (i<=Stack.Top) then
|
if (i>=0) and (i<=Stack.Top) then
|
||||||
Result:=Stack.Stack[i].Typ
|
Result:=Stack.Stack[i].Typ
|
||||||
else
|
else
|
||||||
@ -1279,7 +1279,7 @@ function TFullyAutomaticBeautifier.FindStackPosForBlockCloseAtPos(
|
|||||||
|
|
||||||
procedure EndBlock(aCount: integer = 1);
|
procedure EndBlock(aCount: integer = 1);
|
||||||
begin
|
begin
|
||||||
dec(FindStackPosForBlockCloseAtPos,aCount);
|
dec(AdjustByNextAtom,aCount);
|
||||||
TopTypeValid:=false;
|
TopTypeValid:=false;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1297,13 +1297,15 @@ function TFullyAutomaticBeautifier.FindStackPosForBlockCloseAtPos(
|
|||||||
EndBlock;
|
EndBlock;
|
||||||
if StackTopType in bbtAllIdentifierSections then
|
if StackTopType in bbtAllIdentifierSections then
|
||||||
EndBlock;
|
EndBlock;
|
||||||
|
TopType:=bbtProcedure;
|
||||||
|
TopTypeValid:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function IsMethodDeclaration: boolean;
|
function IsMethodDeclaration: boolean;
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
i:=FindStackPosForBlockCloseAtPos;
|
i:=AdjustByNextAtom;
|
||||||
Result:=(StackTopType in bbtAllProcedures)
|
Result:=(StackTopType in bbtAllProcedures)
|
||||||
and (i>0)
|
and (i>0)
|
||||||
and (Stack.Stack[i-1].Typ=bbtClassSection);
|
and (Stack.Stack[i-1].Typ=bbtClassSection);
|
||||||
@ -1321,7 +1323,7 @@ function TFullyAutomaticBeautifier.FindStackPosForBlockCloseAtPos(
|
|||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
i:=FindStackPosForBlockCloseAtPos;
|
i:=AdjustByNextAtom;
|
||||||
if i>=0 then
|
if i>=0 then
|
||||||
EndBlock(i+1);
|
EndBlock(i+1);
|
||||||
end;
|
end;
|
||||||
@ -1332,7 +1334,7 @@ function TFullyAutomaticBeautifier.FindStackPosForBlockCloseAtPos(
|
|||||||
begin
|
begin
|
||||||
i:=Stack.TopMostIndexOf(BlockTyp);
|
i:=Stack.TopMostIndexOf(BlockTyp);
|
||||||
if i>=0 then
|
if i>=0 then
|
||||||
FindStackPosForBlockCloseAtPos:=i-1;
|
AdjustByNextAtom:=i-1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
@ -1341,7 +1343,7 @@ var
|
|||||||
p: LongInt;
|
p: LongInt;
|
||||||
begin
|
begin
|
||||||
{$IFDEF VerboseIndenter}
|
{$IFDEF VerboseIndenter}
|
||||||
DebugLn(['TFullyAutomaticBeautifier.FindStackPosForBlockCloseAtPos START']);
|
DebugLn(['TFullyAutomaticBeautifier.AdjustByNextAtom START']);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
Result:=Stack.Top;
|
Result:=Stack.Top;
|
||||||
TopType:=bbtNone;
|
TopType:=bbtNone;
|
||||||
@ -1353,11 +1355,11 @@ begin
|
|||||||
p:=CleanPos;
|
p:=CleanPos;
|
||||||
ReadRawNextPascalAtom(Source,p,AtomStart,NestedComments);
|
ReadRawNextPascalAtom(Source,p,AtomStart,NestedComments);
|
||||||
{$IFDEF VerboseIndenter}
|
{$IFDEF VerboseIndenter}
|
||||||
DebugLn(['TFullyAutomaticBeautifier.FindStackPosForBlockCloseAtPos ',AtomStart<>CleanPos,' CleanPos=',dbgstr(copy(Source,CleanPos,10)),' AtomStart=',dbgstr(copy(Source,AtomStart,10))]);
|
DebugLn(['TFullyAutomaticBeautifier.AdjustByNextAtom ',AtomStart<>CleanPos,' CleanPos=',dbgstr(copy(Source,CleanPos,10)),' AtomStart=',dbgstr(copy(Source,AtomStart,10))]);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
if AtomStart<>CleanPos then exit;
|
if AtomStart<>CleanPos then exit;
|
||||||
{$IFDEF VerboseIndenter}
|
{$IFDEF VerboseIndenter}
|
||||||
DebugLn(['TFullyAutomaticBeautifier.FindStackPosForBlockCloseAtPos Atom=',copy(Source,AtomStart,p-AtomStart)]);
|
DebugLn(['TFullyAutomaticBeautifier.AdjustByNextAtom Atom=',copy(Source,AtomStart,p-AtomStart)]);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
TopTypeValid:=true;
|
TopTypeValid:=true;
|
||||||
r:=@Source[AtomStart];
|
r:=@Source[AtomStart];
|
||||||
@ -1515,9 +1517,9 @@ begin
|
|||||||
end;
|
end;
|
||||||
{$IFDEF VerboseIndenter}
|
{$IFDEF VerboseIndenter}
|
||||||
if (Stack.Top<>Result) then
|
if (Stack.Top<>Result) then
|
||||||
DebugLn(['TFullyAutomaticBeautifier.FindStackPosForBlockCloseAtPos block close: Stack.Top=',Stack.Top,' Result=',Result]);
|
DebugLn(['TFullyAutomaticBeautifier.AdjustByNextAtom block close: Stack.Top=',Stack.Top,' Result=',Result]);
|
||||||
if TopTypeValid then
|
if TopTypeValid then
|
||||||
DebugLn(['TFullyAutomaticBeautifier.FindStackPosForBlockCloseAtPos block open: TopType=',FABBlockTypeNames[TopType]]);
|
DebugLn(['TFullyAutomaticBeautifier.AdjustByNextAtom block open: TopType=',FABBlockTypeNames[TopType]]);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1645,14 +1647,14 @@ begin
|
|||||||
SubTypeValid:=false;
|
SubTypeValid:=false;
|
||||||
if UseLineStart then begin
|
if UseLineStart then begin
|
||||||
if InsertText='' then begin
|
if InsertText='' then begin
|
||||||
StackIndex:=FindStackPosForBlockCloseAtPos(Source,CleanPos,
|
StackIndex:=AdjustByNextAtom(Source,CleanPos,
|
||||||
NewNestedComments,Stack,SubType,SubTypeValid);
|
NewNestedComments,Stack,SubType,SubTypeValid);
|
||||||
end else begin
|
end else begin
|
||||||
InsertTextStartPos:=1;
|
InsertTextStartPos:=1;
|
||||||
while (InsertTextStartPos<=length(InsertText))
|
while (InsertTextStartPos<=length(InsertText))
|
||||||
and (InsertText[InsertTextStartPos] in [' ',#9]) do
|
and (InsertText[InsertTextStartPos] in [' ',#9]) do
|
||||||
inc(InsertTextStartPos);
|
inc(InsertTextStartPos);
|
||||||
StackIndex:=FindStackPosForBlockCloseAtPos(InsertText,InsertTextStartPos,
|
StackIndex:=AdjustByNextAtom(InsertText,InsertTextStartPos,
|
||||||
NewNestedComments,Stack,SubType,SubTypeValid);
|
NewNestedComments,Stack,SubType,SubTypeValid);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -1874,7 +1876,7 @@ begin
|
|||||||
Item^.SubType:=bbtNone;
|
Item^.SubType:=bbtNone;
|
||||||
Item^.SubTypeValid:=false;
|
Item^.SubTypeValid:=false;
|
||||||
if UseLineStart then
|
if UseLineStart then
|
||||||
StackIndex:=FindStackPosForBlockCloseAtPos(Source,Item^.CleanPos,
|
StackIndex:=AdjustByNextAtom(Source,Item^.CleanPos,
|
||||||
NewNestedComments,Stack,Item^.SubType,Item^.SubTypeValid);
|
NewNestedComments,Stack,Item^.SubType,Item^.SubTypeValid);
|
||||||
if (StackIndex<0) then begin
|
if (StackIndex<0) then begin
|
||||||
// no context
|
// no context
|
||||||
|
Loading…
Reference in New Issue
Block a user