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>);
|
||||
|
||||
TIndentationMode = (imSpaces, imTabs);
|
||||
|
||||
TCECompiler = (dmd, gdc, ldc);
|
||||
|
||||
// aliased to get a custom prop inspector
|
||||
|
@ -258,6 +260,16 @@ type
|
|||
*)
|
||||
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
|
||||
// supplementatl directories to find background tools
|
||||
additionalPath: string;
|
||||
|
@ -1155,6 +1167,41 @@ begin
|
|||
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
|
||||
registerClasses([TCEPersistentShortcut]);
|
||||
end.
|
||||
|
|
|
@ -31,6 +31,7 @@ type
|
|||
//
|
||||
fShortCuts: TCollection;
|
||||
//
|
||||
fDetectIndentationMode: boolean;
|
||||
fCurrLineAttribs: TSynSelectedColor;
|
||||
fSelAttribs: TSynSelectedColor;
|
||||
fFoldedColor: TSynSelectedColor;
|
||||
|
@ -85,6 +86,7 @@ type
|
|||
property completionMenuWidth: integer read fCompletionMenuWidth write fCompletionMenuWidth;
|
||||
property currentLine: TSynSelectedColor read fCurrLineAttribs write setCurrLineAttribs;
|
||||
property ddocDelay: Integer read fDDocDelay write setDDocDelay;
|
||||
property detectIndentMode: boolean read fDetectIndentationMode write fDetectIndentationMode;
|
||||
property folding: TSynSelectedColor read fFoldedColor write setFoldedColor;
|
||||
property font: TFont read fFont write setFont;
|
||||
property highlighterDlang: TPersistent read fD2Syn write setD2Syn;
|
||||
|
@ -281,6 +283,7 @@ begin
|
|||
background := srcopt.background;
|
||||
lineNumberEvery := srcopt.lineNumberEvery;
|
||||
identifierMatchOptions:=srcopt.identifierMatchOptions;
|
||||
detectIndentMode:=srcopt.detectIndentMode;
|
||||
|
||||
tabulationWidth := srcopt.tabulationWidth;
|
||||
blockIndentation := srcopt.blockIndentation;
|
||||
|
@ -462,6 +465,7 @@ end;
|
|||
|
||||
procedure TCEEditorOptions.docFocused(aDoc: TCESynMemo);
|
||||
begin
|
||||
Assign();
|
||||
end;
|
||||
|
||||
procedure TCEEditorOptions.docChanged(aDoc: TCESynMemo);
|
||||
|
@ -632,6 +636,7 @@ begin
|
|||
anEditor.RightEdge := rightEdge;
|
||||
anEditor.RightEdgeColor := rightEdgeColor;
|
||||
anEditor.IdentifierMatchOptions:= identifierMatchOptions;
|
||||
anEditor.detectIndentMode := detectIndentMode;
|
||||
for i := 0 to anEditor.Keystrokes.Count-1 do
|
||||
begin
|
||||
kst := anEditor.Keystrokes.Items[i];
|
||||
|
|
|
@ -143,6 +143,7 @@ type
|
|||
fAutoCloseCurlyBrace: TBraceAutoCloseStyle;
|
||||
fLexToks: TLexTokenList;
|
||||
fDisableFileDateCheck: boolean;
|
||||
fDetectIndentMode: boolean;
|
||||
procedure setMatchOpts(value: TIdentifierMatchOptions);
|
||||
function getMouseFileBytePos: Integer;
|
||||
procedure changeNotify(Sender: TObject);
|
||||
|
@ -219,6 +220,7 @@ type
|
|||
property isTemporary: boolean read getIfTemp;
|
||||
property TextView;
|
||||
//
|
||||
property detectIndentMode: boolean read fDetectIndentMode write fDetectIndentMode;
|
||||
property disableFileDateCheck: boolean read fDisableFileDateCheck write fDisableFileDateCheck;
|
||||
property MouseStart: Integer read getMouseFileBytePos;
|
||||
property D2Highlighter: TSynD2Syn read fD2Highlighter;
|
||||
|
@ -1387,6 +1389,14 @@ begin
|
|||
loadCache;
|
||||
fCacheLoaded := true;
|
||||
end;
|
||||
//
|
||||
if detectIndentMode then
|
||||
begin
|
||||
case indentationMode(lines) of
|
||||
imTabs: Options:= Options - [eoTabsToSpaces];
|
||||
imSpaces: Options:= Options + [eoTabsToSpaces];
|
||||
end;
|
||||
end;
|
||||
subjDocChanged(TCEMultiDocSubject(fMultiDocSubject), self);
|
||||
end;
|
||||
|
||||
|
|
Loading…
Reference in New Issue