mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-19 11:59:30 +01:00
codetools: auto indent: flag to ignore context
git-svn-id: trunk@22400 -
This commit is contained in:
parent
dae3bc507c
commit
e750aff51a
@ -315,7 +315,9 @@ type
|
||||
procedure Clear;
|
||||
function GetIndent(const Source: string; CleanPos: integer;
|
||||
NewNestedComments: boolean; UseLineStart: boolean;
|
||||
out Indent: TFABIndentationPolicy): boolean;
|
||||
out Indent: TFABIndentationPolicy;
|
||||
ContextLearn: boolean = true // true = learn policies from Source
|
||||
): boolean;
|
||||
function GetIndents(const Source: string; Positions: TFABPositionIndents;
|
||||
NewNestedComments: boolean; UseLineStart: boolean
|
||||
): boolean;
|
||||
@ -1392,7 +1394,8 @@ end;
|
||||
|
||||
function TFullyAutomaticBeautifier.GetIndent(const Source: string;
|
||||
CleanPos: integer; NewNestedComments: boolean;
|
||||
UseLineStart: boolean; out Indent: TFABIndentationPolicy): boolean;
|
||||
UseLineStart: boolean; out Indent: TFABIndentationPolicy;
|
||||
ContextLearn: boolean): boolean;
|
||||
var
|
||||
Block: TBlock;
|
||||
|
||||
@ -1435,9 +1438,11 @@ begin
|
||||
|
||||
Block:=CleanBlock;
|
||||
ParentBlock:=CleanBlock;
|
||||
Policies:=TFABPolicies.Create;
|
||||
Policies:=nil;
|
||||
Stack:=TFABBlockStack.Create;
|
||||
try
|
||||
if ContextLearn then
|
||||
Policies:=TFABPolicies.Create;
|
||||
{$IFDEF ShowCodeBeautifierLearn}
|
||||
Policies.Code:=TCodeBuffer.Create;
|
||||
Policies.Code.Source:=Source;
|
||||
@ -1474,14 +1479,16 @@ begin
|
||||
DebugLn(['TFullyAutomaticBeautifier.GetIndent parsed code in front: context=',FABBlockTypeNames[ParentBlock.Typ],'/',FABBlockTypeNames[Block.Typ],' indent=',GetLineIndentWithTabs(Source,Block.StartPos,DefaultTabWidth)]);
|
||||
if CheckPolicies(Policies,Result) then exit;
|
||||
|
||||
// parse source behind
|
||||
ParseSource(Source,CleanPos,length(Source)+1,NewNestedComments,Stack,Policies);
|
||||
DebugLn(['TFullyAutomaticBeautifier.GetIndent parsed source behind']);
|
||||
if CheckPolicies(Policies,Result) then exit;
|
||||
|
||||
if ContextLearn then begin
|
||||
// parse source behind
|
||||
ParseSource(Source,CleanPos,length(Source)+1,NewNestedComments,Stack,Policies);
|
||||
DebugLn(['TFullyAutomaticBeautifier.GetIndent parsed source behind']);
|
||||
if CheckPolicies(Policies,Result) then exit;
|
||||
end;
|
||||
finally
|
||||
Stack.Free;
|
||||
FreeAndNil(Policies.Code);
|
||||
if Policies<>nil then
|
||||
FreeAndNil(Policies.Code);
|
||||
Policies.Free;
|
||||
end;
|
||||
|
||||
|
||||
@ -615,9 +615,9 @@ type
|
||||
procedure EditorMouseLink(
|
||||
Sender: TObject; X,Y: Integer; var AllowMouseLink: Boolean);
|
||||
function EditorGetIndent(Sender: TObject; Editor: TObject;
|
||||
LogCaret, OldLogCaret: TPoint; FirstLinePos, LastLinePos: Integer;
|
||||
Reason: TSynEditorCommand;
|
||||
SetIndentProc: TSynBeautifierSetIndentProc): Boolean;
|
||||
LogCaret, OldLogCaret: TPoint; FirstLinePos, LastLinePos: Integer;
|
||||
Reason: TSynEditorCommand;
|
||||
SetIndentProc: TSynBeautifierSetIndentProc): Boolean;
|
||||
procedure EditorKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
||||
procedure EditorMouseWheel(Sender: TObject; Shift: TShiftState;
|
||||
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
|
||||
@ -6775,7 +6775,8 @@ end;
|
||||
|
||||
function TSourceNotebook.EditorGetIndent(Sender: TObject; Editor: TObject;
|
||||
LogCaret, OldLogCaret: TPoint; FirstLinePos, LastLinePos: Integer;
|
||||
Reason: TSynEditorCommand; SetIndentProc: TSynBeautifierSetIndentProc): Boolean;
|
||||
Reason: TSynEditorCommand; SetIndentProc: TSynBeautifierSetIndentProc
|
||||
): Boolean;
|
||||
var
|
||||
SrcEdit: TSourceEditor;
|
||||
p: LongInt;
|
||||
@ -6832,7 +6833,7 @@ begin
|
||||
DebugLn(['TSourceNotebook.EditorGetIndent Firstline+1=',SrcEdit.Lines[FirstLinePos+1]]);
|
||||
NestedComments:=CodeToolBoss.GetNestedCommentsFlagForFile(CodeBuf.Filename);
|
||||
if not CodeToolBoss.Indenter.GetIndent(CodeBuf.Source,p,NestedComments,
|
||||
true,NewIndent)
|
||||
true,NewIndent,CodeToolsOpts.IndentContextSensitive)
|
||||
then exit;
|
||||
if not NewIndent.IndentValid then exit;
|
||||
Indent:=NewIndent.Indent;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user