mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-10 22:36:17 +02:00
synedit: license and clean up
git-svn-id: trunk@20468 -
This commit is contained in:
parent
adfc47093d
commit
4454110a0b
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -1557,7 +1557,6 @@ components/synedit/languages/synmacrorecorder.ru.po svneol=native#text/plain
|
||||
components/synedit/languages/synmacrorecorder.ua.po svneol=native#text/plain
|
||||
components/synedit/languages/synmacrorecorder.zh_CN.po svneol=native#text/utf8
|
||||
components/synedit/synbeautifier.pas svneol=native#text/plain
|
||||
components/synedit/synbeautifierpas.pas svneol=native#text/plain
|
||||
components/synedit/syncompletion.pas svneol=native#text/pascal
|
||||
components/synedit/syndesignstringconstants.pas svneol=native#text/plain
|
||||
components/synedit/synedit.inc svneol=native#text/pascal
|
||||
|
@ -1,3 +1,38 @@
|
||||
{-------------------------------------------------------------------------------
|
||||
The contents of this file are subject to the Mozilla Public License
|
||||
Version 1.1 (the "License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
http://www.mozilla.org/MPL/
|
||||
|
||||
Software distributed under the License is distributed on an "AS IS" basis,
|
||||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
|
||||
the specific language governing rights and limitations under the License.
|
||||
|
||||
The Original Code is: SynHighlighterGeneral.pas, released 2000-04-07.
|
||||
The Original Code is based on the mwGeneralSyn.pas file from the
|
||||
mwEdit component suite by Martin Waldenburg and other developers, the Initial
|
||||
Author of this file is Martin Waldenburg.
|
||||
Portions written by Martin Waldenburg are copyright 1999 Martin Waldenburg.
|
||||
All Rights Reserved.
|
||||
|
||||
Contributors to the SynEdit and mwEdit projects are listed in the
|
||||
Contributors.txt file.
|
||||
|
||||
Alternatively, the contents of this file may be used under the terms of the
|
||||
GNU General Public License Version 2 or later (the "GPL"), in which case
|
||||
the provisions of the GPL are applicable instead of those above.
|
||||
If you wish to allow use of your version of this file only under the terms
|
||||
of the GPL and not to allow others to use your version of this file
|
||||
under the MPL, indicate your decision by deleting the provisions above and
|
||||
replace them with the notice and other provisions required by the GPL.
|
||||
If you do not delete the provisions above, a recipient may use your version
|
||||
of this file under either the MPL or the GPL.
|
||||
|
||||
$Id: SynHighlighterGeneral.pas,v 1.3 2000/11/08 22:09:59 mghie Exp $
|
||||
|
||||
You may retrieve the latest version of this file at the SynEdit home page,
|
||||
located at http://SynEdit.SourceForge.net
|
||||
}
|
||||
unit SynBeautifier;
|
||||
|
||||
{$I synedit.inc}
|
||||
|
@ -1,188 +0,0 @@
|
||||
{-------------------------------------------------------------------------------
|
||||
The contents of this file are subject to the Mozilla Public License
|
||||
Version 1.1 (the "License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
http://www.mozilla.org/MPL/
|
||||
Software distributed under the License is distributed on an "AS IS" basis,
|
||||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
|
||||
the specific language governing rights and limitations under the License.
|
||||
-------------------------------------------------------------------------------}
|
||||
{ Examples:
|
||||
indent (begin, asm, try, var, const, type, resourcestring,
|
||||
public, protected, private, published, automated, repeat)
|
||||
begin
|
||||
|
|
||||
|
||||
unindent (end, until)
|
||||
begin
|
||||
|end
|
||||
|
||||
unindent and indent (finally, public, published, private, protected)
|
||||
finally
|
||||
|
|
||||
|
||||
if,else without begin:
|
||||
if expr then
|
||||
|
|
||||
else
|
||||
|
|
||||
|
||||
case
|
||||
case expr of
|
||||
else
|
||||
|
|
||||
end;
|
||||
|
||||
type as modifier:
|
||||
type
|
||||
TColor = type integer;
|
||||
}
|
||||
unit SynBeautifierPas;
|
||||
|
||||
{$I synedit.inc}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, LCLProc, SynEdit, SynBeautifier,
|
||||
SynEditHighlighter, SynHighlighterPas, SynEditTextBase;
|
||||
|
||||
type
|
||||
|
||||
{ TSynBeautifierPas }
|
||||
|
||||
TSynBeautifierPas = class(TSynBeautifier)
|
||||
public
|
||||
function TokenKindIsComment(Kind: integer): boolean;
|
||||
function InComment(Editor: TCustomSynEdit; Lines: TSynEditStrings;
|
||||
XY: TPoint): boolean;
|
||||
procedure ReadPriorToken(Editor: TCustomSynEdit; Lines: TSynEditStrings;
|
||||
var Y, StartX, EndX: integer);
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
{ TSynBeautifierPas }
|
||||
|
||||
procedure TSynBeautifierPas.ReadPriorToken(Editor: TCustomSynEdit;
|
||||
Lines: TSynEditStrings; var Y, StartX, EndX: integer);
|
||||
var
|
||||
TokenStart: Integer;
|
||||
Line: string;
|
||||
Highlighter: TSynCustomHighlighter;
|
||||
Token: String;
|
||||
begin
|
||||
Highlighter:=Editor.Highlighter;
|
||||
if Highlighter=nil then begin
|
||||
Y:=0;
|
||||
exit;
|
||||
end;
|
||||
|
||||
if Y>Lines.Count then begin
|
||||
// cursor after end of code
|
||||
// => move to end of last line
|
||||
Y:=Lines.Count;
|
||||
if Y=0 then exit;
|
||||
StartX:=length(Lines[Y-1])+1;
|
||||
end else if Y<=0 then begin
|
||||
// cursor in front of code => no prior token
|
||||
exit;
|
||||
end;
|
||||
|
||||
Line:=Lines[Y-1];
|
||||
Highlighter.CurrentLines := Lines;
|
||||
Highlighter.StartAtLineIndex(Y - 1);
|
||||
if StartX>length(Line) then begin
|
||||
TokenStart:=length(Line)+1;
|
||||
//TokenType:=Highlighter.GetTokenKind;
|
||||
end else begin
|
||||
while not Highlighter.GetEol do begin
|
||||
TokenStart := Highlighter.GetTokenPos + 1;
|
||||
Token := Highlighter.GetToken;
|
||||
DebugLn(['TSynBeautifierPas.ReadPriorToken Start=',TokenStart,' Token="',Token,'"']);
|
||||
if (StartX >= TokenStart) and (StartX < TokenStart + Length(Token)) then
|
||||
begin
|
||||
DebugLn(['TSynBeautifierPas.ReadPriorToken ']);
|
||||
//TokenType:=Highlighter.GetTokenKind;
|
||||
break;
|
||||
end;
|
||||
Highlighter.Next;
|
||||
end;
|
||||
Highlighter.ContinueNextLine;
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
function TSynBeautifierPas.TokenKindIsComment(Kind: integer): boolean;
|
||||
begin
|
||||
Result:=(ord(tkComment)=Kind) or (ord(tkDirective)=Kind);
|
||||
end;
|
||||
|
||||
function TSynBeautifierPas.InComment(Editor: TCustomSynEdit;
|
||||
Lines: TSynEditStrings; XY: TPoint): boolean;
|
||||
var
|
||||
Highlighter: TSynPasSyn;
|
||||
Line: string;
|
||||
Start: Integer;
|
||||
Token: String;
|
||||
TokenType: LongInt;
|
||||
begin
|
||||
DebugLn(['TSynBeautifierPas.InComment ',dbgs(XY)]);
|
||||
Highlighter:=TSynPasSyn(Editor.Highlighter);
|
||||
if Highlighter=nil then begin
|
||||
DebugLn(['TSynBeautifierPas.InComment missing Highlighter']);
|
||||
exit(false);
|
||||
end;
|
||||
|
||||
if Lines.Count=0 then begin
|
||||
DebugLn(['TSynBeautifierPas.InComment Lines empty']);
|
||||
exit(false); // no code
|
||||
end;
|
||||
|
||||
Highlighter.CurrentLines := Lines;
|
||||
if XY.Y>Lines.Count then begin
|
||||
// cursor after end of code
|
||||
DebugLn(['TSynBeautifierPas.InComment cursor after end of code']);
|
||||
XY.Y:=Lines.Count;
|
||||
Highlighter.StartAtLineIndex(XY.Y - 1);
|
||||
TokenType:=Highlighter.GetTokenKind;
|
||||
end else if XY.Y<=0 then begin
|
||||
// cursor in front of code => no prior token
|
||||
DebugLn(['TSynBeautifierPas.InComment cursor in front of code']);
|
||||
exit(false);
|
||||
end else begin
|
||||
Line:=Lines[XY.Y-1];
|
||||
if XY.X<1 then begin
|
||||
// cursor left of code
|
||||
if XY.Y=1 then begin
|
||||
// cursor in front of code => no prior token
|
||||
DebugLn(['TSynBeautifierPas.InComment cursor in front of code']);
|
||||
exit(false);
|
||||
end;
|
||||
DebugLn(['TSynBeautifierPas.InComment cursor left of code']);
|
||||
Highlighter.StartAtLineIndex(XY.Y - 2);
|
||||
TokenType:=Highlighter.GetTokenKind;
|
||||
end else begin
|
||||
Highlighter.StartAtLineIndex(XY.Y - 1);
|
||||
if XY.X>length(Line) then
|
||||
XY.X:=length(Line)+1;
|
||||
DebugLn(['TSynBeautifierPas.InComment scanning line ...']);
|
||||
while not Highlighter.GetEol do begin
|
||||
Start := Highlighter.GetTokenPos + 1;
|
||||
Token := Highlighter.GetToken;
|
||||
DebugLn(['TSynBeautifierPas.InComment "',Token,'"']);
|
||||
if (XY.X >= Start) and (XY.X < Start + Length(Token)) then begin
|
||||
TokenType := Highlighter.GetTokenKind;
|
||||
break;
|
||||
end;
|
||||
Highlighter.Next;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
DebugLn(['TSynBeautifierPas.InComment ',TokenType]);
|
||||
Result:=TokenKindIsComment(TokenType);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user