mirror of https://gitlab.com/basile.b/dexed.git
add a c++ highlighter
This commit is contained in:
parent
be41ff25e5
commit
dac5f31ecf
|
@ -276,10 +276,15 @@ type
|
||||||
function commonFolder(const files: TStringList): string;
|
function commonFolder(const files: TStringList): string;
|
||||||
|
|
||||||
(**
|
(**
|
||||||
* Returns true if ext matches a file extension whose type is highlightable.
|
* Returns true if ext matches a file extension whose type is highlightable (D)
|
||||||
*)
|
*)
|
||||||
function hasDlangSyntax(const ext: string): boolean;
|
function hasDlangSyntax(const ext: string): boolean;
|
||||||
|
|
||||||
|
(**
|
||||||
|
* Returns true if ext matches a file extension whose type is highlightable (C/C++)
|
||||||
|
*)
|
||||||
|
function hasCppSyntax(const ext: string): boolean;
|
||||||
|
|
||||||
(**
|
(**
|
||||||
* Returns true if ext matches a file extension whose type can be passed as source.
|
* Returns true if ext matches a file extension whose type can be passed as source.
|
||||||
*)
|
*)
|
||||||
|
@ -1237,6 +1242,13 @@ begin
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function hasCppSyntax(const ext: string): boolean;
|
||||||
|
begin
|
||||||
|
result := false;
|
||||||
|
case ext of
|
||||||
|
'.c', '.h', '.cc', '.cpp', '.hpp': result := true;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function isDlangCompilable(const ext: string): boolean;
|
function isDlangCompilable(const ext: string): boolean;
|
||||||
begin
|
begin
|
||||||
|
|
|
@ -689,6 +689,16 @@ begin
|
||||||
if not fResetFontSize then
|
if not fResetFontSize then
|
||||||
anEditor.Font.Size := savedSize;
|
anEditor.Font.Size := savedSize;
|
||||||
|
|
||||||
|
anEditor.CppHighlighter.AsmAttri := anEditor.D2Highlighter.inlineAsm;
|
||||||
|
anEditor.CppHighlighter.CommentAttri := anEditor.D2Highlighter.comments;
|
||||||
|
anEditor.CppHighlighter.DirecAttri := anEditor.D2Highlighter.ddoc;
|
||||||
|
anEditor.CppHighlighter.IdentifierAttri := anEditor.D2Highlighter.identifiers;
|
||||||
|
anEditor.CppHighlighter.KeyAttri := anEditor.D2Highlighter.keywords;
|
||||||
|
anEditor.CppHighlighter.SpaceAttri := anEditor.D2Highlighter.whites;
|
||||||
|
anEditor.CppHighlighter.StringAttri := anEditor.D2Highlighter.strings;
|
||||||
|
anEditor.CppHighlighter.SymbolAttri := anEditor.D2Highlighter.symbols;
|
||||||
|
anEditor.CppHighlighter.NumberAttri := anEditor.D2Highlighter.numbers;
|
||||||
|
|
||||||
anEditor.completionMenu.TheForm.Font.Assign(font);
|
anEditor.completionMenu.TheForm.Font.Assign(font);
|
||||||
anEditor.autoCloseCurlyBrace := fAutoCloseCurlyBrace;
|
anEditor.autoCloseCurlyBrace := fAutoCloseCurlyBrace;
|
||||||
anEditor.autoClosedPairs := fAutoClosedPairs;
|
anEditor.autoClosedPairs := fAutoClosedPairs;
|
||||||
|
|
|
@ -9,7 +9,7 @@ uses
|
||||||
SynEdit, SynPluginSyncroEdit, SynCompletion, SynEditKeyCmds, LazSynEditText,
|
SynEdit, SynPluginSyncroEdit, SynCompletion, SynEditKeyCmds, LazSynEditText,
|
||||||
SynHighlighterLFM, SynEditHighlighter, SynEditMouseCmds, SynEditFoldedView,
|
SynHighlighterLFM, SynEditHighlighter, SynEditMouseCmds, SynEditFoldedView,
|
||||||
SynEditMarks, SynEditTypes, SynHighlighterJScript, SynBeautifier, dialogs,
|
SynEditMarks, SynEditTypes, SynHighlighterJScript, SynBeautifier, dialogs,
|
||||||
md5, Spin, LCLIntf, LazFileUtils, LMessages,
|
md5, Spin, LCLIntf, LazFileUtils, LMessages, SynHighlighterCpp,
|
||||||
//SynEditMarkupFoldColoring,
|
//SynEditMarkupFoldColoring,
|
||||||
Clipbrd, fpjson, jsonparser, LazUTF8, LazUTF8Classes, Buttons, StdCtrls,
|
Clipbrd, fpjson, jsonparser, LazUTF8, LazUTF8Classes, Buttons, StdCtrls,
|
||||||
ce_common, ce_writableComponent, ce_d2syn, ce_txtsyn, ce_dialogs, ce_dastworx,
|
ce_common, ce_writableComponent, ce_d2syn, ce_txtsyn, ce_dialogs, ce_dastworx,
|
||||||
|
@ -157,6 +157,7 @@ type
|
||||||
fMemo: TSynEdit;
|
fMemo: TSynEdit;
|
||||||
fD2Hl: TSynD2Syn;
|
fD2Hl: TSynD2Syn;
|
||||||
fTxtHl: TSynTxtSyn;
|
fTxtHl: TSynTxtSyn;
|
||||||
|
fCppHl: TSynCppSyn;
|
||||||
fSource: TCESynMemo;
|
fSource: TCESynMemo;
|
||||||
procedure updateFromSource;
|
procedure updateFromSource;
|
||||||
protected
|
protected
|
||||||
|
@ -180,7 +181,6 @@ type
|
||||||
fFileDate: double;
|
fFileDate: double;
|
||||||
fCacheLoaded: boolean;
|
fCacheLoaded: boolean;
|
||||||
fIsDSource: boolean;
|
fIsDSource: boolean;
|
||||||
fIsTxtFile: boolean;
|
|
||||||
fFocusForInput: boolean;
|
fFocusForInput: boolean;
|
||||||
fIdentifier: string;
|
fIdentifier: string;
|
||||||
fTempFileName: string;
|
fTempFileName: string;
|
||||||
|
@ -203,6 +203,7 @@ type
|
||||||
fCompletion: TSynCompletion;
|
fCompletion: TSynCompletion;
|
||||||
fD2Highlighter: TSynD2Syn;
|
fD2Highlighter: TSynD2Syn;
|
||||||
fTxtHighlighter: TSynTxtSyn;
|
fTxtHighlighter: TSynTxtSyn;
|
||||||
|
fCppHighlighter: TSynCppSyn;
|
||||||
fImages: TImageList;
|
fImages: TImageList;
|
||||||
fMatchSelectionOpts: TSynSearchOptions;
|
fMatchSelectionOpts: TSynSearchOptions;
|
||||||
fMatchIdentOpts: TSynSearchOptions;
|
fMatchIdentOpts: TSynSearchOptions;
|
||||||
|
@ -377,6 +378,7 @@ type
|
||||||
property MouseBytePosition: Integer read getMouseBytePosition;
|
property MouseBytePosition: Integer read getMouseBytePosition;
|
||||||
property D2Highlighter: TSynD2Syn read fD2Highlighter;
|
property D2Highlighter: TSynD2Syn read fD2Highlighter;
|
||||||
property TxtHighlighter: TSynTxtSyn read fTxtHighlighter;
|
property TxtHighlighter: TSynTxtSyn read fTxtHighlighter;
|
||||||
|
property CppHighlighter: TSynCppSyn read fCppHighlighter;
|
||||||
property defaultFontSize: Integer read fDefaultFontSize write setDefaultFontSize;
|
property defaultFontSize: Integer read fDefaultFontSize write setDefaultFontSize;
|
||||||
property ddocDelay: Integer read fDDocDelay write setDDocDelay;
|
property ddocDelay: Integer read fDDocDelay write setDDocDelay;
|
||||||
property autoDotDelay: Integer read fAutoDotDelay write setAutoDotDelay;
|
property autoDotDelay: Integer read fAutoDotDelay write setAutoDotDelay;
|
||||||
|
@ -864,7 +866,8 @@ begin
|
||||||
fMemo.Options:=fMemo.Options+[eoNoCaret];
|
fMemo.Options:=fMemo.Options+[eoNoCaret];
|
||||||
|
|
||||||
fD2Hl:= TSynD2Syn.create(self);
|
fD2Hl:= TSynD2Syn.create(self);
|
||||||
fTxtHl:= TSynTxtSyn.Create(self);
|
fTxtHl:= TSynTxtSyn.create(self);
|
||||||
|
fCppHl:= TSynCppSyn.create(self);
|
||||||
fSource:= editor;
|
fSource:= editor;
|
||||||
updateFromSource();
|
updateFromSource();
|
||||||
end;
|
end;
|
||||||
|
@ -883,10 +886,13 @@ begin
|
||||||
begin
|
begin
|
||||||
fD2Hl.Assign(fSource.Highlighter);
|
fD2Hl.Assign(fSource.Highlighter);
|
||||||
fTxtHl.Assign(fSource.Highlighter);
|
fTxtHl.Assign(fSource.Highlighter);
|
||||||
|
fCppHl.Assign(fSource.Highlighter);
|
||||||
end;
|
end;
|
||||||
if fSource.Highlighter is TSynD2Syn then
|
if fSource.Highlighter is TSynD2Syn then
|
||||||
fMemo.Highlighter := fD2Hl
|
fMemo.Highlighter := fD2Hl
|
||||||
else
|
else if fSource.Highlighter is TSynCppSyn then
|
||||||
|
fMemo.Highlighter := fCppHl
|
||||||
|
else if fSource.Highlighter is TSynD2Syn then
|
||||||
fMemo.Highlighter := fTxtHl;
|
fMemo.Highlighter := fTxtHl;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
@ -1009,6 +1015,7 @@ begin
|
||||||
|
|
||||||
fD2Highlighter := TSynD2Syn.create(self);
|
fD2Highlighter := TSynD2Syn.create(self);
|
||||||
fTxtHighlighter := TSynTxtSyn.Create(self);
|
fTxtHighlighter := TSynTxtSyn.Create(self);
|
||||||
|
fCppHighlighter := TSynCppSyn.Create(self);
|
||||||
Highlighter := fD2Highlighter;
|
Highlighter := fD2Highlighter;
|
||||||
|
|
||||||
fTempFileName := GetTempDir(false) + 'temp_' + uniqueObjStr(self) + '.d';
|
fTempFileName := GetTempDir(false) + 'temp_' + uniqueObjStr(self) + '.d';
|
||||||
|
@ -3073,7 +3080,6 @@ procedure TCESynMemo.SetHighlighter(const Value: TSynCustomHighlighter);
|
||||||
begin
|
begin
|
||||||
inherited;
|
inherited;
|
||||||
fIsDSource := Highlighter = fD2Highlighter;
|
fIsDSource := Highlighter = fD2Highlighter;
|
||||||
fIsTxtFile := Highlighter = fTxtHighlighter;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCESynMemo.highlightCurrentIdentifier;
|
procedure TCESynMemo.highlightCurrentIdentifier;
|
||||||
|
@ -3118,12 +3124,19 @@ end;
|
||||||
|
|
||||||
procedure TCESynMemo.loadFromFile(const fname: string);
|
procedure TCESynMemo.loadFromFile(const fname: string);
|
||||||
var
|
var
|
||||||
ext: string;
|
e: string;
|
||||||
|
c: boolean;
|
||||||
begin
|
begin
|
||||||
ext := fname.extractFileExt;
|
e := fname.extractFileExt;
|
||||||
fIsDsource := hasDlangSyntax(ext);
|
fIsDsource := hasDlangSyntax(e);
|
||||||
|
c := hasCppSyntax(e);
|
||||||
if not fIsDsource then
|
if not fIsDsource then
|
||||||
Highlighter := TxtSyn;
|
begin
|
||||||
|
if c then
|
||||||
|
Highlighter := CppHighlighter
|
||||||
|
else
|
||||||
|
Highlighter := TxtSyn;
|
||||||
|
end;
|
||||||
Lines.LoadFromFile(fname);
|
Lines.LoadFromFile(fname);
|
||||||
fFilename := fname;
|
fFilename := fname;
|
||||||
FileAge(fFilename, fFileDate);
|
FileAge(fFilename, fFileDate);
|
||||||
|
@ -3158,7 +3171,12 @@ begin
|
||||||
if fIsDsource then
|
if fIsDsource then
|
||||||
Highlighter := fD2Highlighter
|
Highlighter := fD2Highlighter
|
||||||
else if not isProjectDescription then
|
else if not isProjectDescription then
|
||||||
Highlighter := TxtHighlighter;
|
begin
|
||||||
|
if hasCppSyntax(ext) then
|
||||||
|
Highlighter := CppHighlighter
|
||||||
|
else
|
||||||
|
Highlighter := TxtHighlighter;
|
||||||
|
end;
|
||||||
FileAge(fFilename, fFileDate);
|
FileAge(fFilename, fFileDate);
|
||||||
fModified := false;
|
fModified := false;
|
||||||
if fFilename <> fTempFileName then
|
if fFilename <> fTempFileName then
|
||||||
|
|
Loading…
Reference in New Issue