mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-27 11:37:26 +01:00
codetools: indentation: clean up
git-svn-id: trunk@20147 -
This commit is contained in:
parent
30c089e331
commit
244a75d53f
@ -107,7 +107,7 @@ unit CodeBeautifier;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, KeywordFuncLists, CodeCache, BasicCodeTools;
|
Classes, SysUtils, FileProcs, KeywordFuncLists, CodeCache, BasicCodeTools;
|
||||||
|
|
||||||
type
|
type
|
||||||
TBeautifySplit =(
|
TBeautifySplit =(
|
||||||
@ -153,7 +153,8 @@ type
|
|||||||
FAtomCount: integer;
|
FAtomCount: integer;
|
||||||
procedure ParseSource(const Source: string; NewNestedComments: boolean);
|
procedure ParseSource(const Source: string; NewNestedComments: boolean);
|
||||||
function IndexOfAtomInFront(CleanPos: integer): integer;
|
function IndexOfAtomInFront(CleanPos: integer): integer;
|
||||||
function FindContext(CleanPos: integer): TFABBlockType;
|
function FindContext(CleanPos: integer; out AtomInFront: integer
|
||||||
|
): TFABBlockType;
|
||||||
public
|
public
|
||||||
Src: string;
|
Src: string;
|
||||||
SrcLen: integer;
|
SrcLen: integer;
|
||||||
@ -286,19 +287,20 @@ begin
|
|||||||
Result:=-1;
|
Result:=-1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TFullyAutomaticBeautifier.FindContext(CleanPos: integer): TFABBlockType;
|
function TFullyAutomaticBeautifier.FindContext(CleanPos: integer; out
|
||||||
|
AtomInFront: integer): TFABBlockType;
|
||||||
var
|
var
|
||||||
AtomIndex: LongInt;
|
|
||||||
i: LongInt;
|
i: LongInt;
|
||||||
StartPos: LongInt;
|
StartPos: LongInt;
|
||||||
p: PChar;
|
p: PChar;
|
||||||
begin
|
begin
|
||||||
AtomIndex:=IndexOfAtomInFront(CleanPos);
|
AtomInFront:=IndexOfAtomInFront(CleanPos);
|
||||||
if AtomIndex<0 then exit(bbtNone);
|
if AtomInFront<0 then exit(bbtNone);
|
||||||
i:=AtomIndex;
|
i:=AtomInFront;
|
||||||
while i>=0 do begin
|
while i>=0 do begin
|
||||||
StartPos:=FAtomStarts[i];
|
StartPos:=FAtomStarts[i];
|
||||||
p:=@Src[StartPos];
|
p:=@Src[StartPos];
|
||||||
|
DebugLn(['TFullyAutomaticBeautifier.FindContext Atom=',GetAtomString(p,NestedComments)]);
|
||||||
case UpChars[p^] of
|
case UpChars[p^] of
|
||||||
'R':
|
'R':
|
||||||
if CompareIdentifiers('REPEAT',p)=0 then begin
|
if CompareIdentifiers('REPEAT',p)=0 then begin
|
||||||
@ -331,21 +333,22 @@ function TFullyAutomaticBeautifier.GetIndent(const Source: string;
|
|||||||
CleanPos: integer; NewNestedComments: boolean;
|
CleanPos: integer; NewNestedComments: boolean;
|
||||||
out Indent: TFABIndentation): boolean;
|
out Indent: TFABIndentation): boolean;
|
||||||
var
|
var
|
||||||
AtomIndex: LongInt;
|
AtomInFront: LongInt;
|
||||||
|
BlockType: TFABBlockType;
|
||||||
begin
|
begin
|
||||||
FillByte(Indent,SizeOf(Indent),0);
|
FillByte(Indent,SizeOf(Indent),0);
|
||||||
|
|
||||||
// parse source
|
// parse source
|
||||||
ParseSource(Source,NewNestedComments);
|
ParseSource(Source,NewNestedComments);
|
||||||
|
DebugLn(['TFullyAutomaticBeautifier.GetIndent FAtomCount=',FAtomCount]);
|
||||||
|
|
||||||
// find context
|
BlockType:=FindContext(CleanPos,AtomInFront);
|
||||||
AtomIndex:=IndexOfAtomInFront(CleanPos);
|
if AtomInFront<0 then begin
|
||||||
if AtomIndex<0 then begin
|
|
||||||
// in comments/space in front of any code
|
// in comments/space in front of any code
|
||||||
exit(false);
|
exit(false);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
FindContext(CleanPos);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user