codetools: BeautifyStatement: do not split comments

git-svn-id: trunk@30435 -
This commit is contained in:
mattias 2011-04-23 14:47:22 +00:00
parent 1ca433e5b8
commit d8d7ef7d44
4 changed files with 20 additions and 8 deletions

View File

@ -1072,7 +1072,7 @@ var
IndentLen: Integer;
begin
if NewAtom='' then exit;
//DebugLn('[TBeautifyCodeOptions.AddAtom] NewAtom=',NewAtom,' s="',s,'"');
//DebugLn(['[TBeautifyCodeOptions.AddAtom] NewAtom="',dbgstr(NewAtom),'"']);
// beautify identifier
if IsIdentStartChar[NewAtom[1]]
@ -1123,7 +1123,7 @@ begin
and (LastSplitPos>1) then begin
// new atom does not fit into the line and there is a split position
// -> split line
//DebugLn(['[TBeautifyCodeOptions.AddAtom] NEW LINE CurLineLen=',CurLineLen,' NewAtom=',NewAtom,' "',copy(CurCode,LastSplitPos,5),'" LineLength=',LineLength]);
//DebugLn(['[TBeautifyCodeOptions.AddAtom] NEW LINE CurLineLen=',CurLineLen,' NewAtom="',dbgstr(NewAtom),'" LastSplitPos="',dbgstr(copy(CurCode,LastSplitPos-5,5))+'|'+dbgstr(copy(CurCode,LastSplitPos,5)),'" LineLength=',LineLength]);
RestLineLen:=length(CurCode)-LastSplitPos+1;
IndentLen:=Indent+GetLineIndent(CurCode,LastSrcLineStart)+HiddenIndent;
CurCode:=copy(CurCode,1,LastSplitPos-1)+LineEnd
@ -1143,7 +1143,7 @@ begin
HiddenIndent:=0;
end;
end;
//debugln(['TBeautifyCodeOptions.AddAtom ',dbgstr(CurCode),' ',CurLineLen]);
//debugln(['TBeautifyCodeOptions.AddAtom CurCode="',dbgstr(CurCode),'" CurLineLen=',CurLineLen]);
end;
procedure TBeautifyCodeOptions.ReadNextAtom;
@ -1153,7 +1153,7 @@ begin
if AtomStart<=SrcLen then begin
c1:=Src[CurPos];
case c1 of
'a'..'z','A'..'Z','_': // identifier
'a'..'z','A'..'Z','_': // identifier or keyword
begin
CurAtomType:=atIdentifier;
repeat
@ -1163,6 +1163,13 @@ begin
then
CurAtomType:=atKeyword;
end;
#128..#255: // UTF8
begin
CurAtomType:=atIdentifier;
repeat
inc(CurPos);
until (CurPos>SrcLen) or not (IsIdentChar[Src[CurPos]] or (Src[CurPos]>=#128));
end;
#10,#13: // line break
begin
EndComment('/',CurPos);
@ -1484,7 +1491,8 @@ begin
end;
if (not (CurAtomType in DoNotSplitLineInFront))
and (not (LastAtomType in DoNotSplitLineAfter)) then
and (not (LastAtomType in DoNotSplitLineAfter))
and (CommentLvl=0) then
LastSplitPos:=length(Result)+1;
{DebugLn('SPLIT LINE CurPos='+dbgs(CurPos)+' CurAtom="'+CurAtom+'"'
+' CurAtomType='+AtomTypeNames[CurAtomType]

View File

@ -25,7 +25,7 @@ unit codetools_linesplitting_options;
interface
uses
Classes, SysUtils, Forms, StdCtrls, SynEdit,
Classes, SysUtils, LCLProc, Forms, StdCtrls, SynEdit,
SourceChanger, IDEOptionsIntf, EditorOptions, atom_checkboxes_options;
type
@ -77,14 +77,16 @@ const
LineSplitExampleText =
'function F(Sender: TObject; const Val1, Val2, Val3:char; ' +
'var Var1, Var2: array of const): integer;'#13 +
'const i=1+2+3;';
'const i=1+2+3; // ąčęęėįšųūž';
begin
if BeautifyCodeOptions = nil then
Exit;
WriteBeautifyCodeOptions(BeautifyCodeOptions);
BeautifyCodeOptions.LineLength := 1;
debugln(['TCodetoolsLineSplittingOptionsFrame.UpdateSplitLineExample AAA1']);
SplitPreviewSynEdit.Text :=
BeautifyCodeOptions.BeautifyStatement(LineSplitExampleText, 0);
debugln(['TCodetoolsLineSplittingOptionsFrame.UpdateSplitLineExample AAA2']);
end;
procedure TCodetoolsLineSplittingOptionsFrame.UpdatePreviewSettings;

View File

@ -81,6 +81,7 @@ const
' A:=@B.C;D:=3;E:=X[5];'#13 +
' {$I unit1.lrs}'#13 +
' {$R-}{$R+}'#13 +
' // ąčęęėįšųūž'#13+
'end;';
begin
if BeautifyCodeOptions = nil then

View File

@ -560,9 +560,10 @@ begin
LastLine:=StringConstSynEdit.Lines[EndPos.Y-StartPos.Y];
RightSide:=copy(LastLine,EndPos.X,length(LastLine)-EndPos.X+1);
NewSource:=LeftSide+NewString+RightSide;
NewSource:=LeftSide+NewString;
with CodeToolBoss.SourceChangeCache.BeautifyCodeOptions do
NewSource:=BeautifyStatement(NewSource,0);
NewSource:=NewString+RightSide;
ResourceStringValue:=FormatStringConstant;
end;