mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-07 10:57:39 +01:00
SynEdit: PascalBeautifier, fixes for comment indent/prefix-continuation
git-svn-id: trunk@39602 -
This commit is contained in:
parent
4e85ebf6ba
commit
b00e519138
@ -196,8 +196,8 @@ type
|
|||||||
// By default indent is the same as for none comment lines (none overrides sciAlignOpen)
|
// 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)
|
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(); (*"
|
sciAlignOpen, // Indent to real opening pos on first line, if comment does not start at BOL "Foo(); (*"
|
||||||
|
// Will force every new line back to Align.
|
||||||
// sciAlignOpenOnce // 2nd line only, thes sciNone or default (must not have sciAlignOpen)
|
// To align only once, use IndentFirstLineExtra=MaxInt
|
||||||
|
|
||||||
// sciAdd...: if (only if) previous line had started with the opening token "(*" or "{".
|
// sciAdd...: if (only if) previous line had started with the opening token "(*" or "{".
|
||||||
// or if sciAlignOpen is set
|
// or if sciAlignOpen is set
|
||||||
@ -207,6 +207,8 @@ type
|
|||||||
// in case of scmMatchAtAsterisk, 1 space is added. ("(" only)
|
// in case of scmMatchAtAsterisk, 1 space is added. ("(" only)
|
||||||
sciAddPastTokenIndent, // Adds any indent found past the opening token "(*", "{" or "//".
|
sciAddPastTokenIndent, // Adds any indent found past the opening token "(*", "{" or "//".
|
||||||
// For "//" this is added after the nem "//", but before the prefix.
|
// 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 ignore spaces, that are matched.
|
||||||
// flag to be smart, if not matched
|
// flag to be smart, if not matched
|
||||||
@ -247,7 +249,7 @@ type
|
|||||||
FEolPostfix: Array [TSynCommentType] of String;
|
FEolPostfix: Array [TSynCommentType] of String;
|
||||||
FEolSkipLongerLine: Array [TSynCommentType] of Boolean;
|
FEolSkipLongerLine: Array [TSynCommentType] of Boolean;
|
||||||
|
|
||||||
FExtenbSlashCommentMode: TSynCommentExtendMode;
|
FExtendSlashCommentMode: TSynCommentExtendMode;
|
||||||
|
|
||||||
private
|
private
|
||||||
FPasHighlighter: TSynPasSyn;
|
FPasHighlighter: TSynPasSyn;
|
||||||
@ -392,8 +394,8 @@ type
|
|||||||
// *** coments with //
|
// *** coments with //
|
||||||
// Continue only, if Extended
|
// Continue only, if Extended
|
||||||
|
|
||||||
property ExtenbSlashCommentMode: TSynCommentExtendMode read FExtenbSlashCommentMode
|
property ExtendSlashCommentMode: TSynCommentExtendMode read FExtendSlashCommentMode
|
||||||
write FExtenbSlashCommentMode;
|
write FExtendSlashCommentMode;
|
||||||
|
|
||||||
property SlashIndentMode: TSynCommentIndentFlags read FIndentMode[sctSlash]
|
property SlashIndentMode: TSynCommentIndentFlags read FIndentMode[sctSlash]
|
||||||
write FIndentMode[sctSlash];
|
write FIndentMode[sctSlash];
|
||||||
@ -923,8 +925,8 @@ var
|
|||||||
function IsFoldTypeEnabled(AType: TSynCommentType): Boolean;
|
function IsFoldTypeEnabled(AType: TSynCommentType): Boolean;
|
||||||
begin
|
begin
|
||||||
Result := ( ( (AType <> sctSlash) or
|
Result := ( ( (AType <> sctSlash) or
|
||||||
( ((not FCaretAtEOL) and (FExtenbSlashCommentMode <> sceNever)) or
|
( ((not FCaretAtEOL) and (FExtendSlashCommentMode <> sceNever)) or
|
||||||
((FCaretAtEOL) and not(FExtenbSlashCommentMode in [sceNever, sceSplitLine, sceMatchingSplitLine]))
|
((FCaretAtEOL) and not(FExtendSlashCommentMode in [sceNever, sceSplitLine, sceMatchingSplitLine]))
|
||||||
)
|
)
|
||||||
) and
|
) and
|
||||||
( (FIndentMode[AType] <> []) or
|
( (FIndentMode[AType] <> []) or
|
||||||
@ -981,8 +983,8 @@ begin
|
|||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
if (FCurrentLines[ToIdx(WorkLine)-1] <> '') and
|
if (FCurrentLines[ToIdx(WorkLine)-1] <> '') and
|
||||||
(FExtenbSlashCommentMode <> sceNever) and
|
(FExtendSlashCommentMode <> sceNever) and
|
||||||
( (not FCaretAtEOL) or not(FExtenbSlashCommentMode in [sceSplitLine, sceMatchingSplitLine]) )
|
( (not FCaretAtEOL) or not(FExtendSlashCommentMode in [sceSplitLine, sceMatchingSplitLine]) )
|
||||||
then begin
|
then begin
|
||||||
PrevLineShlasCol := GetSlashStartColumn;
|
PrevLineShlasCol := GetSlashStartColumn;
|
||||||
if PrevLineShlasCol > 0 then
|
if PrevLineShlasCol > 0 then
|
||||||
@ -1004,9 +1006,9 @@ begin
|
|||||||
|
|
||||||
// Check if we need extend
|
// Check if we need extend
|
||||||
ExtendSlash := False;
|
ExtendSlash := False;
|
||||||
if FoldTyp = sctSlash then begin
|
if (FoldTyp = sctSlash) and (ACaret.OldLineBytePos.x > GetSlashStartColumn+2) then begin
|
||||||
// Check if extension is needed
|
// Check if extension is needed
|
||||||
case FExtenbSlashCommentMode of
|
case FExtendSlashCommentMode of
|
||||||
sceAlways: ExtendSlash := True;
|
sceAlways: ExtendSlash := True;
|
||||||
sceSplitLine: ExtendSlash := not FCaretAtEOL;
|
sceSplitLine: ExtendSlash := not FCaretAtEOL;
|
||||||
sceMatching: ExtendSlash := CheckMatch(FoldTyp);
|
sceMatching: ExtendSlash := CheckMatch(FoldTyp);
|
||||||
@ -1053,7 +1055,7 @@ begin
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
if (FIndentMode[FoldTyp] * [sciNone, sciAlignOpen] = [sciAlignOpen]) and
|
if (FIndentMode[FoldTyp] * [sciNone, sciAlignOpen] = [sciAlignOpen]) and
|
||||||
(GetCommentStartCol > 1)
|
(GetCommentStartCol > 0)
|
||||||
then begin
|
then begin
|
||||||
Indent := FCurrentLines.LogicalToPhysicalCol(FCurrentLines[ToIdx(GetFirstCommentLine)], ToIdx(GetFirstCommentLine), GetCommentStartCol-1);
|
Indent := FCurrentLines.LogicalToPhysicalCol(FCurrentLines[ToIdx(GetFirstCommentLine)], ToIdx(GetFirstCommentLine), GetCommentStartCol-1);
|
||||||
if FIndentFirstLineMax[FoldTyp] > 0
|
if FIndentFirstLineMax[FoldTyp] > 0
|
||||||
@ -1090,7 +1092,7 @@ begin
|
|||||||
(Matching or ExtendSlash or (sciApplyIndentForNoMatch in FIndentMode[FoldTyp]) or
|
(Matching or ExtendSlash or (sciApplyIndentForNoMatch in FIndentMode[FoldTyp]) or
|
||||||
(FCommentMode[FoldTyp] = sccPrefixAlways) );
|
(FCommentMode[FoldTyp] = sccPrefixAlways) );
|
||||||
|
|
||||||
// Spaces for (* or {
|
// sciAddTokenLen -- Spaces for (* or {
|
||||||
if BeSmart and (sciAddTokenLen in FIndentMode[FoldTyp])
|
if BeSmart and (sciAddTokenLen in FIndentMode[FoldTyp])
|
||||||
then begin
|
then begin
|
||||||
case FoldTyp of
|
case FoldTyp of
|
||||||
@ -1104,7 +1106,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
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
|
if BeSmart and (sciAddPastTokenIndent in FIndentMode[FoldTyp]) and (GetCommentStartCol > 0) // foundStartCol
|
||||||
then begin
|
then begin
|
||||||
case FoldTyp of
|
case FoldTyp of
|
||||||
@ -1136,10 +1138,12 @@ begin
|
|||||||
FGetLineAfterComment := True;
|
FGetLineAfterComment := True;
|
||||||
try
|
try
|
||||||
GetIndentInfo(WorkLine, s, Indent, GetFirstCommentLine);
|
GetIndentInfo(WorkLine, s, Indent, GetFirstCommentLine);
|
||||||
if s <> '' then begin;
|
if s <> '' then begin
|
||||||
FCurrentLines.EditInsert(1 + FLogicalIndentLen, WorkLine, s);
|
FCurrentLines.EditInsert(1 + FLogicalIndentLen, WorkLine, s);
|
||||||
FLogicalIndentLen := FLogicalIndentLen + length(s);
|
FLogicalIndentLen := FLogicalIndentLen + length(s); // logical (Indent is phisical)
|
||||||
end;
|
end
|
||||||
|
else
|
||||||
|
FLogicalIndentLen := FLogicalIndentLen + Indent; // maybe position caret
|
||||||
finally
|
finally
|
||||||
FGetLineAfterComment := False;
|
FGetLineAfterComment := False;
|
||||||
end;
|
end;
|
||||||
@ -1192,7 +1196,7 @@ begin
|
|||||||
FEolSkipLongerLine[sctBor] := False;
|
FEolSkipLongerLine[sctBor] := False;
|
||||||
|
|
||||||
|
|
||||||
FExtenbSlashCommentMode := sceNever;
|
FExtendSlashCommentMode := sceNever;
|
||||||
|
|
||||||
FIndentMode[sctSlash] := [];
|
FIndentMode[sctSlash] := [];
|
||||||
FIndentFirstLineExtra[sctSlash] := '';
|
FIndentFirstLineExtra[sctSlash] := '';
|
||||||
@ -1224,7 +1228,7 @@ begin
|
|||||||
inherited Assign(Src);
|
inherited Assign(Src);
|
||||||
if not(Src is TSynBeautifierPascal) then exit;
|
if not(Src is TSynBeautifierPascal) then exit;
|
||||||
|
|
||||||
FExtenbSlashCommentMode := TSynBeautifierPascal(Src).FExtenbSlashCommentMode;
|
FExtendSlashCommentMode := TSynBeautifierPascal(Src).FExtendSlashCommentMode;
|
||||||
|
|
||||||
for i := low(TSynCommentType) to high(TSynCommentType) do begin
|
for i := low(TSynCommentType) to high(TSynCommentType) do begin
|
||||||
FIndentMode[i] := TSynBeautifierPascal(Src).FIndentMode[i];
|
FIndentMode[i] := TSynBeautifierPascal(Src).FIndentMode[i];
|
||||||
|
|||||||
@ -903,7 +903,7 @@ type
|
|||||||
end;
|
end;
|
||||||
sctSlash:
|
sctSlash:
|
||||||
with Beautifier do begin
|
with Beautifier do begin
|
||||||
ExtenbSlashCommentMode := AExtenbSlash;
|
ExtendSlashCommentMode := AExtenbSlash;
|
||||||
|
|
||||||
SlashIndentMode := AIndentMode;
|
SlashIndentMode := AIndentMode;
|
||||||
SlashIndentFirstLineMax := AIndentFirstLineMax;
|
SlashIndentFirstLineMax := AIndentFirstLineMax;
|
||||||
@ -1005,6 +1005,7 @@ begin
|
|||||||
Beautifier.IndentType := sbitCopySpaceTab;
|
Beautifier.IndentType := sbitCopySpaceTab;
|
||||||
|
|
||||||
{%region Bor (Curly) }
|
{%region Bor (Curly) }
|
||||||
|
|
||||||
ConfigBeautifier(sctBor, [sciAddTokenLen, sciAddPastTokenIndent], 0, '',
|
ConfigBeautifier(sctBor, [sciAddTokenLen, sciAddPastTokenIndent], 0, '',
|
||||||
sccPrefixMatch, scmMatchAfterOpening, sclMatchPrev,
|
sccPrefixMatch, scmMatchAfterOpening, sclMatchPrev,
|
||||||
sbitSpace,
|
sbitSpace,
|
||||||
@ -1016,6 +1017,13 @@ begin
|
|||||||
DoNewLine('', 7, 4, 6, 5, [4, ' * c', ' * ' ]); // 4:" * c|"
|
DoNewLine('', 7, 4, 6, 5, [4, ' * c', ' * ' ]); // 4:" * c|"
|
||||||
DoNewLine('', 5, 3, 5, 4, [3, ' *', ' * b' ]); // 3:" *| b"
|
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']);
|
DoSetText('Curly, not matching', [2, ' {+ abc']);
|
||||||
DoNewLine('', 7, 2, 3, 3, [2, ' {+ a', ' bc']); // 2:" {* a|bc"
|
DoNewLine('', 7, 2, 3, 3, [2, ' {+ a', ' bc']); // 2:" {* a|bc"
|
||||||
|
|
||||||
@ -1188,6 +1196,13 @@ begin
|
|||||||
DoSetText('not BOL matching', [2, ' ;;;{* abc']);
|
DoSetText('not BOL matching', [2, ' ;;;{* abc']);
|
||||||
DoNewLine('after 1st', 10, 2, 8, 3, [2, ' ;;;{* a', ' * bc']); // 2:" ;{* a|bc"
|
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"
|
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
|
end
|
||||||
else begin // [sciAddTokenLen]
|
else begin // [sciAddTokenLen]
|
||||||
// Indent / matching
|
// Indent / matching
|
||||||
@ -1199,6 +1214,13 @@ begin
|
|||||||
DoSetText('not BOL matching', [2, ' ;;;{* abc']);
|
DoSetText('not BOL matching', [2, ' ;;;{* abc']);
|
||||||
DoNewLine('after 1st', 10, 2, 9, 3, [2, ' ;;;{* a', ' * bc']); // 2:" ;{* a|bc"
|
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"
|
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;
|
end;
|
||||||
PopBaseName;
|
PopBaseName;
|
||||||
|
|
||||||
@ -1659,6 +1681,39 @@ begin
|
|||||||
PopBaseName;
|
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;
|
PopBaseName;
|
||||||
{%endregion [sciAlignOpen] }
|
{%endregion [sciAlignOpen] }
|
||||||
|
|
||||||
@ -1717,7 +1772,6 @@ begin
|
|||||||
Beautifier.BorIndentMode := [sciAddTokenLen, sciApplyIndentForNoMatch];
|
Beautifier.BorIndentMode := [sciAddTokenLen, sciApplyIndentForNoMatch];
|
||||||
DoSetText('sccPrefixAlways; NOT matching, apply', [2, ' {+ abc']);
|
DoSetText('sccPrefixAlways; NOT matching, apply', [2, ' {+ abc']);
|
||||||
DoNewLine('after 1st', 7, 2, 5, 3, [2, ' {+ a', ' *bc']); // 2:" {* a|bc"
|
DoNewLine('after 1st', 7, 2, 5, 3, [2, ' {+ a', ' *bc']); // 2:" {* a|bc"
|
||||||
|
|
||||||
{%endregion Bor (Curly) }
|
{%endregion Bor (Curly) }
|
||||||
|
|
||||||
|
|
||||||
@ -1813,6 +1867,22 @@ begin
|
|||||||
DoSetText('Slash No match, split', [2, ' // abc']);
|
DoSetText('Slash No match, split', [2, ' // abc']);
|
||||||
DoNewLine('', 7, 2, 6, 3, [2, ' // a', ' // bc']); // 2:" // a|bc"
|
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 // }
|
{%endregion Slash // }
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user