SynEdit: PascalBeautifier, fixes for comment indent/prefix-continuation

git-svn-id: trunk@39602 -
This commit is contained in:
martin 2012-12-20 20:29:17 +00:00
parent 4e85ebf6ba
commit b00e519138
2 changed files with 95 additions and 21 deletions

View File

@ -196,8 +196,8 @@ type
// By default indent is the same as for none comment lines (none overrides sciAlignOpen)
sciNone, // Does not Indent comment lines (Prefix may contain a fixed indent)
sciAlignOpen, // Indent to real opening pos on first line, if comment does not start at BOL "Foo(); (*"
// sciAlignOpenOnce // 2nd line only, thes sciNone or default (must not have sciAlignOpen)
// Will force every new line back to Align.
// To align only once, use IndentFirstLineExtra=MaxInt
// sciAdd...: if (only if) previous line had started with the opening token "(*" or "{".
// or if sciAlignOpen is set
@ -207,6 +207,8 @@ type
// in case of scmMatchAtAsterisk, 1 space is added. ("(" only)
sciAddPastTokenIndent, // Adds any indent found past the opening token "(*", "{" or "//".
// For "//" this is added after the nem "//", but before the prefix.
//sciAddPastTokenIndentMatchLine, // Only if first line matches. (Do not specify sciAddPastTokenIndent)
// Adds matched and unmatched spaces.
// flag to ignore spaces, that are matched.
// flag to be smart, if not matched
@ -247,7 +249,7 @@ type
FEolPostfix: Array [TSynCommentType] of String;
FEolSkipLongerLine: Array [TSynCommentType] of Boolean;
FExtenbSlashCommentMode: TSynCommentExtendMode;
FExtendSlashCommentMode: TSynCommentExtendMode;
private
FPasHighlighter: TSynPasSyn;
@ -392,8 +394,8 @@ type
// *** coments with //
// Continue only, if Extended
property ExtenbSlashCommentMode: TSynCommentExtendMode read FExtenbSlashCommentMode
write FExtenbSlashCommentMode;
property ExtendSlashCommentMode: TSynCommentExtendMode read FExtendSlashCommentMode
write FExtendSlashCommentMode;
property SlashIndentMode: TSynCommentIndentFlags read FIndentMode[sctSlash]
write FIndentMode[sctSlash];
@ -923,8 +925,8 @@ var
function IsFoldTypeEnabled(AType: TSynCommentType): Boolean;
begin
Result := ( ( (AType <> sctSlash) or
( ((not FCaretAtEOL) and (FExtenbSlashCommentMode <> sceNever)) or
((FCaretAtEOL) and not(FExtenbSlashCommentMode in [sceNever, sceSplitLine, sceMatchingSplitLine]))
( ((not FCaretAtEOL) and (FExtendSlashCommentMode <> sceNever)) or
((FCaretAtEOL) and not(FExtendSlashCommentMode in [sceNever, sceSplitLine, sceMatchingSplitLine]))
)
) and
( (FIndentMode[AType] <> []) or
@ -981,8 +983,8 @@ begin
else
begin
if (FCurrentLines[ToIdx(WorkLine)-1] <> '') and
(FExtenbSlashCommentMode <> sceNever) and
( (not FCaretAtEOL) or not(FExtenbSlashCommentMode in [sceSplitLine, sceMatchingSplitLine]) )
(FExtendSlashCommentMode <> sceNever) and
( (not FCaretAtEOL) or not(FExtendSlashCommentMode in [sceSplitLine, sceMatchingSplitLine]) )
then begin
PrevLineShlasCol := GetSlashStartColumn;
if PrevLineShlasCol > 0 then
@ -1004,9 +1006,9 @@ begin
// Check if we need extend
ExtendSlash := False;
if FoldTyp = sctSlash then begin
if (FoldTyp = sctSlash) and (ACaret.OldLineBytePos.x > GetSlashStartColumn+2) then begin
// Check if extension is needed
case FExtenbSlashCommentMode of
case FExtendSlashCommentMode of
sceAlways: ExtendSlash := True;
sceSplitLine: ExtendSlash := not FCaretAtEOL;
sceMatching: ExtendSlash := CheckMatch(FoldTyp);
@ -1053,7 +1055,7 @@ begin
end
else
if (FIndentMode[FoldTyp] * [sciNone, sciAlignOpen] = [sciAlignOpen]) and
(GetCommentStartCol > 1)
(GetCommentStartCol > 0)
then begin
Indent := FCurrentLines.LogicalToPhysicalCol(FCurrentLines[ToIdx(GetFirstCommentLine)], ToIdx(GetFirstCommentLine), GetCommentStartCol-1);
if FIndentFirstLineMax[FoldTyp] > 0
@ -1090,7 +1092,7 @@ begin
(Matching or ExtendSlash or (sciApplyIndentForNoMatch in FIndentMode[FoldTyp]) or
(FCommentMode[FoldTyp] = sccPrefixAlways) );
// Spaces for (* or {
// sciAddTokenLen -- Spaces for (* or {
if BeSmart and (sciAddTokenLen in FIndentMode[FoldTyp])
then begin
case FoldTyp of
@ -1104,7 +1106,7 @@ begin
end;
end;
// Spaces from after (* or { (to go befare prefix e.g " { * foo")
// sciAddPastTokenIndent -- Spaces from after (* or { (to go befare prefix e.g " { * foo")
if BeSmart and (sciAddPastTokenIndent in FIndentMode[FoldTyp]) and (GetCommentStartCol > 0) // foundStartCol
then begin
case FoldTyp of
@ -1136,10 +1138,12 @@ begin
FGetLineAfterComment := True;
try
GetIndentInfo(WorkLine, s, Indent, GetFirstCommentLine);
if s <> '' then begin;
if s <> '' then begin
FCurrentLines.EditInsert(1 + FLogicalIndentLen, WorkLine, s);
FLogicalIndentLen := FLogicalIndentLen + length(s);
end;
FLogicalIndentLen := FLogicalIndentLen + length(s); // logical (Indent is phisical)
end
else
FLogicalIndentLen := FLogicalIndentLen + Indent; // maybe position caret
finally
FGetLineAfterComment := False;
end;
@ -1192,7 +1196,7 @@ begin
FEolSkipLongerLine[sctBor] := False;
FExtenbSlashCommentMode := sceNever;
FExtendSlashCommentMode := sceNever;
FIndentMode[sctSlash] := [];
FIndentFirstLineExtra[sctSlash] := '';
@ -1224,7 +1228,7 @@ begin
inherited Assign(Src);
if not(Src is TSynBeautifierPascal) then exit;
FExtenbSlashCommentMode := TSynBeautifierPascal(Src).FExtenbSlashCommentMode;
FExtendSlashCommentMode := TSynBeautifierPascal(Src).FExtendSlashCommentMode;
for i := low(TSynCommentType) to high(TSynCommentType) do begin
FIndentMode[i] := TSynBeautifierPascal(Src).FIndentMode[i];

View File

@ -903,7 +903,7 @@ type
end;
sctSlash:
with Beautifier do begin
ExtenbSlashCommentMode := AExtenbSlash;
ExtendSlashCommentMode := AExtenbSlash;
SlashIndentMode := AIndentMode;
SlashIndentFirstLineMax := AIndentFirstLineMax;
@ -1005,6 +1005,7 @@ begin
Beautifier.IndentType := sbitCopySpaceTab;
{%region Bor (Curly) }
ConfigBeautifier(sctBor, [sciAddTokenLen, sciAddPastTokenIndent], 0, '',
sccPrefixMatch, scmMatchAfterOpening, sclMatchPrev,
sbitSpace,
@ -1016,6 +1017,13 @@ begin
DoNewLine('', 7, 4, 6, 5, [4, ' * c', ' * ' ]); // 4:" * c|"
DoNewLine('', 5, 3, 5, 4, [3, ' *', ' * b' ]); // 3:" *| b"
DoSetText('Curly simple 2', [2, ' {* abc', ' * ']);
DoNewLine('', 5, 3, 5, 4, [3, ' * ', ' * ']);
DoSetText('Curly simple 3', [2, ' {*', ' *']);
DoNewLine('', 4, 3, 4, 4, [3, ' *', ' *']);
DoSetText('Curly, not matching', [2, ' {+ abc']);
DoNewLine('', 7, 2, 3, 3, [2, ' {+ a', ' bc']); // 2:" {* a|bc"
@ -1188,6 +1196,13 @@ begin
DoSetText('not BOL matching', [2, ' ;;;{* abc']);
DoNewLine('after 1st', 10, 2, 8, 3, [2, ' ;;;{* a', ' * bc']); // 2:" ;{* a|bc"
DoNewLine('any line', 9, 3, 8, 4, [3, ' * b', ' * c']); // 3:" * b|c"
// Check_that_Indent_is_NOT_restored // SEE Check_that_Indent_is_restored
// Indent, not BOL / matching // AnsiIndentFirstLineMax applied
DoSetText('NOT restore Align', [2, ' ;;;{* abc', ' *']);
if ParentIndentType = sbitPositionCaret
then DoNewLine('after 2nd', 4, 3, 5, 4, [3, ' *', ' *']) // NOT added post indent of 1
else DoNewLine('after 2nd', 4, 3, 5, 4, [3, ' *', ' * ']); // added post indent of 1
end
else begin // [sciAddTokenLen]
// Indent / matching
@ -1199,6 +1214,13 @@ begin
DoSetText('not BOL matching', [2, ' ;;;{* abc']);
DoNewLine('after 1st', 10, 2, 9, 3, [2, ' ;;;{* a', ' * bc']); // 2:" ;{* a|bc"
DoNewLine('any line', 10, 3, 9, 4, [3, ' * b', ' * c']); // 3:" * b|c"
// Check_that_Indent_is_NOT_restored // SEE Check_that_Indent_is_restored
// Indent, not BOL / matching // AnsiIndentFirstLineMax applied
DoSetText('NOT restore Align', [2, ' ;;;{* abc', ' *']);
if ParentIndentType = sbitPositionCaret
then DoNewLine('after 2nd', 4, 3, 5, 4, [3, ' *', ' *'])
else DoNewLine('after 2nd', 4, 3, 5, 4, [3, ' *', ' * ']);
end;
PopBaseName;
@ -1659,6 +1681,39 @@ begin
PopBaseName;
**** *)
// Check_that_Indent_is_restored SEE Check_that_Indent_is_NOT_restored
PushBaseName('Max='+IntToStr(10));
ConfigBeautifier(sctBor, [sciAlignOpen] + ExtraIndentFlags, 0, '',
sccPrefixMatch, scmMatchAfterOpening, MatchLine,
sbitSpace,
'^\s*\*', '*');
if not (sciAddTokenLen in ExtraIndentFlags) then begin
// Indent, not BOL / matching // AnsiIndentFirstLineMax applied
DoSetText('restore Align', [2, ' ;;;{* abc', ' *']);
if ParentIndentType = sbitPositionCaret
then DoNewLine('after 2nd', 4, 3, 8, 4, [3, ' *', ' *'])
else DoNewLine('after 2nd', 4, 3, 8, 4, [3, ' *', ' * ']);
DoSetText('restore Align', [2, ' ;;;{* abc', ' *', ' *']);
if ParentIndentType = sbitPositionCaret
then DoNewLine('any line', 4, 4, 8, 5, [4, ' *', ' *'])
else DoNewLine('any line', 4, 4, 8, 5, [4, ' *', ' * ']);
end
else begin // [sciAddTokenLen]
// Indent, not BOL / matching // AnsiIndentFirstLineMax applied
DoSetText('restore Align', [2, ' ;;;{* abc', ' *']);
if ParentIndentType = sbitPositionCaret
then DoNewLine('after 2nd', 4, 3, 9, 4, [3, ' *', ' *'])
else DoNewLine('after 2nd', 4, 3, 9, 4, [3, ' *', ' * ']);
DoSetText('restore Align', [2, ' ;;;{* abc', ' *', ' *']);
if ParentIndentType = sbitPositionCaret
then DoNewLine('any line', 4, 4, 9, 5, [4, ' *', ' *'])
else DoNewLine('any line', 4, 4, 9, 5, [4, ' *', ' * ']);
end;
PopBaseName;
PopBaseName;
{%endregion [sciAlignOpen] }
@ -1717,7 +1772,6 @@ begin
Beautifier.BorIndentMode := [sciAddTokenLen, sciApplyIndentForNoMatch];
DoSetText('sccPrefixAlways; NOT matching, apply', [2, ' {+ abc']);
DoNewLine('after 1st', 7, 2, 5, 3, [2, ' {+ a', ' *bc']); // 2:" {* a|bc"
{%endregion Bor (Curly) }
@ -1813,6 +1867,22 @@ begin
DoSetText('Slash No match, split', [2, ' // abc']);
DoNewLine('', 7, 2, 6, 3, [2, ' // a', ' // bc']); // 2:" // a|bc"
// aligOpen (single and multiline)
ConfigBeautifier(sctSlash, [sciAlignOpen, sciAddTokenLen, sciAddPastTokenIndent], 0, '',
sccPrefixAlways, scmMatchAfterOpening, sclMatchPrev,
sbitSpace,
'^.?', '',
sceAlways);
DoSetText('Slash sciAlignOpen', [2, ' ;;; // abc']);
DoNewLine('first', 11, 2, 10, 3, [2, ' ;;; // a', ' // bc']); // 2:" // a|bc"
DoNewLine('any', 11, 3, 10, 4, [2, ' // bc', ' // c']); // 2:" // b|c"
DoSetText('Slash sciAlignOpen realign', [2, ' ;;; // abc', ' // de']);
DoNewLine('2nd', 9, 3, 10, 4, [3, ' // d', ' // e']); // 3:" // d|e"
DoSetText('Slash sciAlignOpen realign', [2, ' ;;; // abc', ' //', ' // de']);
DoNewLine('3rd', 9, 4, 10, 5, [4, ' // d', ' // e']); // 3:" // d|e"
{%endregion Slash // }