mirror of https://gitlab.com/basile.b/dexed.git
add option to auto detect the indentation mode (tabs|spaces), close #45
This commit is contained in:
parent
c957a0099d
commit
393f8c97b4
|
@ -27,6 +27,8 @@ type
|
||||||
|
|
||||||
TIntByString = class(specialize TFPGMap<string, integer>);
|
TIntByString = class(specialize TFPGMap<string, integer>);
|
||||||
|
|
||||||
|
TIndentationMode = (imSpaces, imTabs);
|
||||||
|
|
||||||
TCECompiler = (dmd, gdc, ldc);
|
TCECompiler = (dmd, gdc, ldc);
|
||||||
|
|
||||||
// aliased to get a custom prop inspector
|
// aliased to get a custom prop inspector
|
||||||
|
@ -258,6 +260,16 @@ type
|
||||||
*)
|
*)
|
||||||
function globToReg(const glob: string ): string;
|
function globToReg(const glob: string ): string;
|
||||||
|
|
||||||
|
(**
|
||||||
|
* Detects the main indetation mode used in a file
|
||||||
|
*)
|
||||||
|
function indentationMode(strings: TStrings): TIndentationMode;
|
||||||
|
|
||||||
|
(**
|
||||||
|
* Detects the main indetation mode used in a file
|
||||||
|
*)
|
||||||
|
function indentationMode(const fname: string): TIndentationMode;
|
||||||
|
|
||||||
var
|
var
|
||||||
// supplementatl directories to find background tools
|
// supplementatl directories to find background tools
|
||||||
additionalPath: string;
|
additionalPath: string;
|
||||||
|
@ -1155,6 +1167,41 @@ begin
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function indentationMode(strings: TStrings): TIndentationMode;
|
||||||
|
var
|
||||||
|
i: integer;
|
||||||
|
s: string;
|
||||||
|
tabs: integer = 0;
|
||||||
|
spcs: integer = 0;
|
||||||
|
begin
|
||||||
|
for s in strings do
|
||||||
|
for i := 1 to s.length do
|
||||||
|
begin
|
||||||
|
case s[i] of
|
||||||
|
#9: tabs += 1;
|
||||||
|
' ': spcs += 1;
|
||||||
|
else break;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
if spcs >= tabs then
|
||||||
|
result := imSpaces
|
||||||
|
else
|
||||||
|
result := imTabs;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function indentationMode(const fname: string): TIndentationMode;
|
||||||
|
var
|
||||||
|
str: TStringList;
|
||||||
|
begin
|
||||||
|
str := TStringList.Create;
|
||||||
|
try
|
||||||
|
str.LoadFromFile(fname);
|
||||||
|
result := indentationMode(str);
|
||||||
|
finally
|
||||||
|
str.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
registerClasses([TCEPersistentShortcut]);
|
registerClasses([TCEPersistentShortcut]);
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -31,6 +31,7 @@ type
|
||||||
//
|
//
|
||||||
fShortCuts: TCollection;
|
fShortCuts: TCollection;
|
||||||
//
|
//
|
||||||
|
fDetectIndentationMode: boolean;
|
||||||
fCurrLineAttribs: TSynSelectedColor;
|
fCurrLineAttribs: TSynSelectedColor;
|
||||||
fSelAttribs: TSynSelectedColor;
|
fSelAttribs: TSynSelectedColor;
|
||||||
fFoldedColor: TSynSelectedColor;
|
fFoldedColor: TSynSelectedColor;
|
||||||
|
@ -85,6 +86,7 @@ type
|
||||||
property completionMenuWidth: integer read fCompletionMenuWidth write fCompletionMenuWidth;
|
property completionMenuWidth: integer read fCompletionMenuWidth write fCompletionMenuWidth;
|
||||||
property currentLine: TSynSelectedColor read fCurrLineAttribs write setCurrLineAttribs;
|
property currentLine: TSynSelectedColor read fCurrLineAttribs write setCurrLineAttribs;
|
||||||
property ddocDelay: Integer read fDDocDelay write setDDocDelay;
|
property ddocDelay: Integer read fDDocDelay write setDDocDelay;
|
||||||
|
property detectIndentMode: boolean read fDetectIndentationMode write fDetectIndentationMode;
|
||||||
property folding: TSynSelectedColor read fFoldedColor write setFoldedColor;
|
property folding: TSynSelectedColor read fFoldedColor write setFoldedColor;
|
||||||
property font: TFont read fFont write setFont;
|
property font: TFont read fFont write setFont;
|
||||||
property highlighterDlang: TPersistent read fD2Syn write setD2Syn;
|
property highlighterDlang: TPersistent read fD2Syn write setD2Syn;
|
||||||
|
@ -281,6 +283,7 @@ begin
|
||||||
background := srcopt.background;
|
background := srcopt.background;
|
||||||
lineNumberEvery := srcopt.lineNumberEvery;
|
lineNumberEvery := srcopt.lineNumberEvery;
|
||||||
identifierMatchOptions:=srcopt.identifierMatchOptions;
|
identifierMatchOptions:=srcopt.identifierMatchOptions;
|
||||||
|
detectIndentMode:=srcopt.detectIndentMode;
|
||||||
|
|
||||||
tabulationWidth := srcopt.tabulationWidth;
|
tabulationWidth := srcopt.tabulationWidth;
|
||||||
blockIndentation := srcopt.blockIndentation;
|
blockIndentation := srcopt.blockIndentation;
|
||||||
|
@ -462,6 +465,7 @@ end;
|
||||||
|
|
||||||
procedure TCEEditorOptions.docFocused(aDoc: TCESynMemo);
|
procedure TCEEditorOptions.docFocused(aDoc: TCESynMemo);
|
||||||
begin
|
begin
|
||||||
|
Assign();
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCEEditorOptions.docChanged(aDoc: TCESynMemo);
|
procedure TCEEditorOptions.docChanged(aDoc: TCESynMemo);
|
||||||
|
@ -632,6 +636,7 @@ begin
|
||||||
anEditor.RightEdge := rightEdge;
|
anEditor.RightEdge := rightEdge;
|
||||||
anEditor.RightEdgeColor := rightEdgeColor;
|
anEditor.RightEdgeColor := rightEdgeColor;
|
||||||
anEditor.IdentifierMatchOptions:= identifierMatchOptions;
|
anEditor.IdentifierMatchOptions:= identifierMatchOptions;
|
||||||
|
anEditor.detectIndentMode := detectIndentMode;
|
||||||
for i := 0 to anEditor.Keystrokes.Count-1 do
|
for i := 0 to anEditor.Keystrokes.Count-1 do
|
||||||
begin
|
begin
|
||||||
kst := anEditor.Keystrokes.Items[i];
|
kst := anEditor.Keystrokes.Items[i];
|
||||||
|
|
|
@ -143,6 +143,7 @@ type
|
||||||
fAutoCloseCurlyBrace: TBraceAutoCloseStyle;
|
fAutoCloseCurlyBrace: TBraceAutoCloseStyle;
|
||||||
fLexToks: TLexTokenList;
|
fLexToks: TLexTokenList;
|
||||||
fDisableFileDateCheck: boolean;
|
fDisableFileDateCheck: boolean;
|
||||||
|
fDetectIndentMode: boolean;
|
||||||
procedure setMatchOpts(value: TIdentifierMatchOptions);
|
procedure setMatchOpts(value: TIdentifierMatchOptions);
|
||||||
function getMouseFileBytePos: Integer;
|
function getMouseFileBytePos: Integer;
|
||||||
procedure changeNotify(Sender: TObject);
|
procedure changeNotify(Sender: TObject);
|
||||||
|
@ -219,6 +220,7 @@ type
|
||||||
property isTemporary: boolean read getIfTemp;
|
property isTemporary: boolean read getIfTemp;
|
||||||
property TextView;
|
property TextView;
|
||||||
//
|
//
|
||||||
|
property detectIndentMode: boolean read fDetectIndentMode write fDetectIndentMode;
|
||||||
property disableFileDateCheck: boolean read fDisableFileDateCheck write fDisableFileDateCheck;
|
property disableFileDateCheck: boolean read fDisableFileDateCheck write fDisableFileDateCheck;
|
||||||
property MouseStart: Integer read getMouseFileBytePos;
|
property MouseStart: Integer read getMouseFileBytePos;
|
||||||
property D2Highlighter: TSynD2Syn read fD2Highlighter;
|
property D2Highlighter: TSynD2Syn read fD2Highlighter;
|
||||||
|
@ -1387,6 +1389,14 @@ begin
|
||||||
loadCache;
|
loadCache;
|
||||||
fCacheLoaded := true;
|
fCacheLoaded := true;
|
||||||
end;
|
end;
|
||||||
|
//
|
||||||
|
if detectIndentMode then
|
||||||
|
begin
|
||||||
|
case indentationMode(lines) of
|
||||||
|
imTabs: Options:= Options - [eoTabsToSpaces];
|
||||||
|
imSpaces: Options:= Options + [eoTabsToSpaces];
|
||||||
|
end;
|
||||||
|
end;
|
||||||
subjDocChanged(TCEMultiDocSubject(fMultiDocSubject), self);
|
subjDocChanged(TCEMultiDocSubject(fMultiDocSubject), self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue