fixed code beautifying for compiler directives

git-svn-id: trunk@7621 -
This commit is contained in:
mattias 2005-09-04 08:11:10 +00:00
parent 692146e306
commit 1b5dea0408
6 changed files with 54 additions and 32 deletions

View File

@ -109,6 +109,8 @@ type
DoNotSplitLineAfter: TAtomTypes; DoNotSplitLineAfter: TAtomTypes;
DoInsertSpaceInFront: TAtomTypes; DoInsertSpaceInFront: TAtomTypes;
DoInsertSpaceAfter: TAtomTypes; DoInsertSpaceAfter: TAtomTypes;
DoNotInsertSpaceInFront: TAtomTypes;
DoNotInsertSpaceAfter: TAtomTypes;
PropertyReadIdentPrefix: string; PropertyReadIdentPrefix: string;
PropertyWriteIdentPrefix: string; PropertyWriteIdentPrefix: string;
PropertyStoredIdentPostfix: string; PropertyStoredIdentPostfix: string;
@ -256,6 +258,8 @@ const
DefaultDoNotSplitLineAfter: TAtomTypes = [atColon,atAt,atPoint,atKeyWord]; DefaultDoNotSplitLineAfter: TAtomTypes = [atColon,atAt,atPoint,atKeyWord];
DefaultDoInsertSpaceInFront: TAtomTypes = []; DefaultDoInsertSpaceInFront: TAtomTypes = [];
DefaultDoInsertSpaceAfter: TAtomTypes = [atColon,atComma,atSemicolon]; DefaultDoInsertSpaceAfter: TAtomTypes = [atColon,atComma,atSemicolon];
DefaultDoNotInsertSpaceInFront: TAtomTypes = [];
DefaultDoNotInsertSpaceAfter: TAtomTypes = [atDirectiveStart];
function AtomTypeNameToType(const s: string): TAtomType; function AtomTypeNameToType(const s: string): TAtomType;
function WordPolicyNameToPolicy(const s: string): TWordPolicy; function WordPolicyNameToPolicy(const s: string): TWordPolicy;
@ -939,6 +943,8 @@ begin
DoNotSplitLineAfter:=DefaultDoNotSplitLineAfter; DoNotSplitLineAfter:=DefaultDoNotSplitLineAfter;
DoInsertSpaceInFront:=DefaultDoInsertSpaceInFront; DoInsertSpaceInFront:=DefaultDoInsertSpaceInFront;
DoInsertSpaceAfter:=DefaultDoInsertSpaceAfter; DoInsertSpaceAfter:=DefaultDoInsertSpaceAfter;
DoNotInsertSpaceInFront:=DefaultDoInsertSpaceInFront;
DoNotInsertSpaceAfter:=DefaultDoInsertSpaceAfter;
PropertyReadIdentPrefix:='Get'; PropertyReadIdentPrefix:='Get';
PropertyWriteIdentPrefix:='Set'; PropertyWriteIdentPrefix:='Set';
PropertyStoredIdentPostfix:='IsStored'; PropertyStoredIdentPostfix:='IsStored';
@ -1127,6 +1133,10 @@ begin
if (CurPos<=SrcLen) and (Src[CurPos]='$') then begin if (CurPos<=SrcLen) and (Src[CurPos]='$') then begin
inc(CurPos); inc(CurPos);
CurAtomType:=atDirectiveStart; CurAtomType:=atDirectiveStart;
while (CurPos<=SrcLen) and (IsIdentChar[Src[CurPos]]) do
inc(CurPos);
if (CurPos<=SrcLen) and (Src[CurPos] in ['+','-']) then
inc(CurPos);
end else begin end else begin
CurAtomType:=atCommentStart; CurAtomType:=atCommentStart;
end; end;
@ -1144,6 +1154,10 @@ begin
if (CurPos<=SrcLen) and (Src[CurPos]='$') then begin if (CurPos<=SrcLen) and (Src[CurPos]='$') then begin
inc(CurPos); inc(CurPos);
CurAtomType:=atDirectiveStart; CurAtomType:=atDirectiveStart;
while (CurPos<=SrcLen) and (IsIdentChar[Src[CurPos]]) do
inc(CurPos);
if (CurPos<=SrcLen) and (Src[CurPos] in ['+','-']) then
inc(CurPos);
end else begin end else begin
CurAtomType:=atCommentStart; CurAtomType:=atCommentStart;
end; end;
@ -1169,6 +1183,10 @@ begin
if (CurPos<=SrcLen) and (Src[CurPos]='$') then begin if (CurPos<=SrcLen) and (Src[CurPos]='$') then begin
inc(CurPos); inc(CurPos);
CurAtomType:=atDirectiveStart; CurAtomType:=atDirectiveStart;
while (CurPos<=SrcLen) and (IsIdentChar[Src[CurPos]]) do
inc(CurPos);
if (CurPos<=SrcLen) and (Src[CurPos] in ['+','-']) then
inc(CurPos);
end else begin end else begin
CurAtomType:=atCommentStart; CurAtomType:=atCommentStart;
end; end;
@ -1221,6 +1239,18 @@ begin
{$ENDIF} {$ENDIF}
end; end;
function TBeautifyCodeOptions.BeautifyStatement(const AStatement: string;
IndentSize: integer): string;
begin
Result:=BeautifyStatement(AStatement,IndentSize,[]);
end;
function TBeautifyCodeOptions.BeautifyStatementLeftAligned(
const AStatement: string; IndentSize: integer): string;
begin
Result:=BeautifyStatement(AStatement,IndentSize,[bcfNoIndentOnBreakLine]);
end;
function TBeautifyCodeOptions.BeautifyStatement(const AStatement: string; function TBeautifyCodeOptions.BeautifyStatement(const AStatement: string;
IndentSize: integer; BeautifyFlags: TBeautifyCodeFlags): string; IndentSize: integer; BeautifyFlags: TBeautifyCodeFlags): string;
var CurAtom: string; var CurAtom: string;
@ -1262,9 +1292,11 @@ begin
break; break;
until false; until false;
if ((Result='') or (Result[length(Result)]<>' ')) if ((Result='') or (Result[length(Result)]<>' '))
and (not (CurAtomType in DoNotInsertSpaceInFront))
and (not (LastAtomType in DoNotInsertSpaceAfter))
and ((CurAtomType in DoInsertSpaceInFront) and ((CurAtomType in DoInsertSpaceInFront)
or (LastAtomType in DoInsertSpaceAfter)) or (LastAtomType in DoInsertSpaceAfter))
and (CurAtom<>'$') then then
AddAtom(Result,' '); AddAtom(Result,' ');
if (not (CurAtomType in DoNotSplitLineInFront)) if (not (CurAtomType in DoNotSplitLineInFront))
and (not (LastAtomType in DoNotSplitLineAfter)) then and (not (LastAtomType in DoNotSplitLineAfter)) then
@ -1284,18 +1316,6 @@ begin
//DebugLn('**********************************************************'); //DebugLn('**********************************************************');
end; end;
function TBeautifyCodeOptions.BeautifyStatement(const AStatement: string;
IndentSize: integer): string;
begin
Result:=BeautifyStatement(AStatement,IndentSize,[]);
end;
function TBeautifyCodeOptions.BeautifyStatementLeftAligned(
const AStatement: string; IndentSize: integer): string;
begin
Result:=BeautifyStatement(AStatement,IndentSize,[bcfNoIndentOnBreakLine]);
end;
function TBeautifyCodeOptions.AddClassAndNameToProc(const AProcCode, AClassName, function TBeautifyCodeOptions.AddClassAndNameToProc(const AProcCode, AClassName,
AMethodName: string): string; AMethodName: string): string;
var StartPos, NamePos, ProcLen: integer; var StartPos, NamePos, ProcLen: integer;

View File

@ -2,19 +2,19 @@
This source is only used to compile and install the package. This source is only used to compile and install the package.
} }
unit JPEGForLazarus; unit JPEGForLazarus;
interface interface
uses uses
LazJPEG, LazarusPackageIntf; LazJPEG, LazarusPackageIntf;
implementation implementation
procedure Register; procedure Register;
begin begin
end; end;
initialization initialization
RegisterPackage('JPEGForLazarus', @Register); RegisterPackage('JPEGForLazarus',@Register);
end. end.

View File

@ -2,20 +2,20 @@
This source is only used to compile and install the package. This source is only used to compile and install the package.
} }
unit Printer4Lazarus; unit Printer4Lazarus;
interface interface
uses uses
PrintersDlgs, OSPrinters, LazarusPackageIntf; PrintersDlgs, OSPrinters, LazarusPackageIntf;
implementation implementation
procedure Register; procedure Register;
begin begin
RegisterUnit('PrintersDlgs', @PrintersDlgs.Register); RegisterUnit('PrintersDlgs',@PrintersDlgs.Register);
end; end;
initialization initialization
RegisterPackage('Printer4Lazarus', @Register); RegisterPackage('Printer4Lazarus',@Register);
end. end.

View File

@ -2,21 +2,21 @@
This source is only used to compile and install the package. This source is only used to compile and install the package.
} }
unit RunTimeTypeInfoControls; unit RunTimeTypeInfoControls;
interface interface
uses uses
RTTICtrls, RTTIGrids, LazarusPackageIntf; RTTICtrls, RTTIGrids, LazarusPackageIntf;
implementation implementation
procedure Register; procedure Register;
begin begin
RegisterUnit('RTTICtrls', @RTTICtrls.Register); RegisterUnit('RTTICtrls',@RTTICtrls.Register);
RegisterUnit('RTTIGrids', @RTTIGrids.Register); RegisterUnit('RTTIGrids',@RTTIGrids.Register);
end; end;
initialization initialization
RegisterPackage('RunTimeTypeInfoControls', @Register); RegisterPackage('RunTimeTypeInfoControls',@Register);
end. end.

View File

@ -275,6 +275,7 @@ const
+'begin'#13 +'begin'#13
+' A:=@B.C;D:=3;'#13 +' A:=@B.C;D:=3;'#13
+' {$I unit1.lrs}'#13 +' {$I unit1.lrs}'#13
+' {$R-}{$R+}'#13
+'end;'; +'end;';
function AtomTypeDescriptionToType(const s: string): TAtomType; function AtomTypeDescriptionToType(const s: string): TAtomType;

View File

@ -158,6 +158,7 @@ begin
inherited Create(nil); inherited Create(nil);
OnKeyDown :=@PromptDialogKeyDown; OnKeyDown :=@PromptDialogKeyDown;
//debugln('TPromptDialog.CreateMessageDialog A ButtonCount=',dbgs(ButtonCount));
ControlStyle:= ControlStyle-[csSetCaption]; ControlStyle:= ControlStyle-[csSetCaption];
BorderStyle := bsDialog; BorderStyle := bsDialog;