// static
void cbEditor::InternalSetEditorStyleBeforeFileOpen(cbStyledTextCtrl* control)
{
if (!control)
return;
......
......
// NOTE: duplicate line in editorconfigurationdlg.cpp (ctor)
control->SetEOLMode( mgr->ReadInt(_T("/eol/eolmode"), platform::windows ? wxSCI_EOL_CRLF : wxSCI_EOL_LF)); // Windows takes CR+LF, other platforms LF only
control->SetScrollWidthTracking( mgr->ReadBool(_T("/margin/scroll_width_tracking"), false));
control->SetMultipleSelection( mgr->ReadBool(_T("/selection/multi_select"), false));
control->SetAdditionalSelectionTyping(mgr->ReadBool(_T("/selection/multi_typing"), false));
if (mgr->ReadBool(_T("/selection/use_vspace"), false))
control->SetVirtualSpaceOptions(wxSCI_SCVS_RECTANGULARSELECTION | wxSCI_SCVS_USERACCESSIBLE);
else
control->SetVirtualSpaceOptions(wxSCI_SCVS_NONE);
}
void SciTEBase::DiscoverEOLSetting() {
SetEol();
if (props.GetInt("eol.auto")) {
int linesCR;
int linesLF;
int linesCRLF;
CountLineEnds(linesCR, linesLF, linesCRLF);
if (((linesLF >= linesCR) && (linesLF > linesCRLF)) || ((linesLF > linesCR) && (linesLF >= linesCRLF)))
wEditor.Call(SCI_SETEOLMODE, SC_EOL_LF);
else if (((linesCR >= linesLF) && (linesCR > linesCRLF)) || ((linesCR > linesLF) && (linesCR >= linesCRLF)))
wEditor.Call(SCI_SETEOLMODE, SC_EOL_CR);
else if (((linesCRLF >= linesLF) && (linesCRLF > linesCR)) || ((linesCRLF > linesLF) && (linesCRLF >= linesCR)))
wEditor.Call(SCI_SETEOLMODE, SC_EOL_CRLF);
}
}
I'm confused (though I think you want the correct thing, but brain is not working well during the last weeks, so I'm not sure).Hi, thomas, sorry about the confusion, I'm not a English native speaker, so my English may be poor.
To clarify, with "add many LF" do you mean "change editor's EOL mode to file's EOL mode" or do you mean "change all line endings in the file"?I say "add many LF" which means when I hit the enter key many times, the editor add many lines which have LF styled EOL.
You basically want anything typed into a file to be whatever the file was before, correct?Yes, What I want is to let the editor automatically detect which EOL is used in the original file, then the new added line should still use same type of EOL.
Also, what if the file, like many files from OSS projects is mixed already?For how to detect a files EOL, I think it is simple, just scan the first lines of the file, and set the EOL of the whole file as it is, I think SciTe use this kind of detection.
void SciTEBase::CountLineEnds(int &linesCR, int &linesLF, int &linesCRLF) {
linesCR = 0;
linesLF = 0;
linesCRLF = 0;
int lengthDoc = LengthDocument();
char chPrev = ' ';
TextReader acc(wEditor);
char chNext = acc.SafeGetCharAt(0);
for (int i = 0; i < lengthDoc; i++) {
char ch = chNext;
chNext = acc.SafeGetCharAt(i + 1);
if (ch == '\r') {
if (chNext == '\n')
linesCRLF++;
else
linesCR++;
} else if (ch == '\n') {
if (chPrev != '\r') {
linesLF++;
}
} else if (i > 1000000) {
return;
}
chPrev = ch;
}
}
OK about my brain? :)Yours is hopefully ok, it's mine that isn't good.
(Now, I even do not understand what does "Ensure consistent EOLs" used for, so it will take some time to read the source)
Index: cbeditor.cpp
===================================================================
--- cbeditor.cpp (revision 8249)
+++ cbeditor.cpp (working copy)
@@ -731,6 +731,39 @@
END_EVENT_TABLE()
+
+// Count the EOL in the opened file
+static void CountLineEnds(cbStyledTextCtrl* control, int &linesCR, int &linesLF, int &linesCRLF)
+{
+ linesCR = 0;
+ linesLF = 0;
+ linesCRLF = 0;
+
+ //int GetCharAt(int pos)
+ //int GetLength() const;
+ int lengthDoc = control->GetLength();
+ char chPrev = ' ';
+
+ char chNext = control->GetCharAt(0);
+ for (int i = 0; i < lengthDoc; i++) {
+ char ch = chNext;
+ chNext = control->GetCharAt(i + 1);
+ if (ch == '\r') {
+ if (chNext == '\n')
+ linesCRLF++;
+ else
+ linesCR++;
+ } else if (ch == '\n') {
+ if (chPrev != '\r') {
+ linesLF++;
+ }
+ } else if (i > 1000000) {
+ return;
+ }
+ chPrev = ch;
+ }
+}
+
// class constructor
cbEditor::cbEditor(wxWindow* parent, const wxString& filename, EditorColourSet* theme)
: EditorBase(parent, filename),
@@ -1557,7 +1590,6 @@
control->SetMarginWidth(C_CHANGEBAR_MARGIN, 0);
// NOTE: duplicate line in editorconfigurationdlg.cpp (ctor)
- control->SetEOLMode( mgr->ReadInt(_T("/eol/eolmode"), platform::windows ? wxSCI_EOL_CRLF : wxSCI_EOL_LF)); // Windows takes CR+LF, other platforms LF only
control->SetScrollWidthTracking( mgr->ReadBool(_T("/margin/scroll_width_tracking"), false));
control->SetMultipleSelection( mgr->ReadBool(_T("/selection/multi_select"), false));
control->SetAdditionalSelectionTyping(mgr->ReadBool(_T("/selection/multi_typing"), false));
@@ -1575,6 +1607,23 @@
ConfigManager* mgr = Manager::Get()->GetConfigManager(_T("editor"));
+ // set the EOL, fall back value: Windows takes CR+LF, other platforms LF only
+ int eolMode = mgr->ReadInt(_T("/eol/eolmode"), platform::windows ? wxSCI_EOL_CRLF : wxSCI_EOL_LF);
+ if (eolMode == 3) //auto detect the eol
+ {
+ int linesCR;
+ int linesLF;
+ int linesCRLF;
+ CountLineEnds(control, linesCR, linesLF, linesCRLF);
+ if (((linesLF >= linesCR) && (linesLF > linesCRLF)) || ((linesLF > linesCR) && (linesLF >= linesCRLF)))
+ eolMode = wxSCI_EOL_LF;
+ else if (((linesCR >= linesLF) && (linesCR > linesCRLF)) || ((linesCR > linesLF) && (linesCR >= linesCRLF)))
+ eolMode = wxSCI_EOL_CR;
+ else if (((linesCRLF >= linesLF) && (linesCRLF > linesCR)) || ((linesCRLF > linesLF) && (linesCRLF >= linesCR)))
+ eolMode = wxSCI_EOL_CRLF;
+ }
+ control->SetEOLMode(eolMode);
+
// Interpret #if/#else/#endif to grey out code that is not active
control->SetProperty(_T("lexer.cpp.track.preprocessor"), mgr->ReadBool(_T("/track_preprocessor"), true) ? _T("1") : _T("0"));
Index: resources/editor_configuration.xrc
===================================================================
--- resources/editor_configuration.xrc (revision 8249)
+++ resources/editor_configuration.xrc (working copy)
@@ -200,6 +200,7 @@
<item>CR LF</item>
<item>CR</item>
<item>LF</item>
+ <item>AUTO</item>
</content>
<style>wxCB_READONLY</style>
</object>
if (((linesLF >= linesCR) && (linesLF > linesCRLF)) || ((linesLF > linesCR) && (linesLF >= linesCRLF)))
{
eolMode = wxSCI_EOL_LF;
if((linesCR>0) || (linesCRLF>0))
{
wxBell();
InfoWindow::Display(_("Mixed Line Endings"), _("Mixed line endings found, setting mode \"LF\""), 1000);
}
}
else if (((linesCR >= linesLF) && (linesCR > linesCRLF)) || ((linesCR > linesLF) && (linesCR >= linesCRLF)))
{
eolMode = wxSCI_EOL_CR;
if((linesLF>0) || (linesCRLF>0))
{
wxBell();
InfoWindow::Display(_("Mixed Line Endings"), _("Mixed line endings found, setting mode \"CR\""), 1000);
}
}
else if (((linesCRLF >= linesLF) && (linesCRLF > linesCR)) || ((linesCRLF > linesLF) && (linesCRLF >= linesCR)))
{
eolMode = wxSCI_EOL_CRLF;
if((linesCR>0) || (linesLF>0))
{
wxBell();
InfoWindow::Display(_("Mixed Line Endings"), _("Mixed line endings found, setting mode \"CR-LF\""), 1000);
}
}
Index: cbeditor.cpp
===================================================================
--- cbeditor.cpp (revision 8249)
+++ cbeditor.cpp (working copy)
@@ -731,6 +731,42 @@
END_EVENT_TABLE()
+// Count lines of EOL style in the opened file
+static void CountLineEnds(cbStyledTextCtrl* control, int &linesCR, int &linesLF, int &linesCRLF)
+{
+ linesCR = 0;
+ linesLF = 0;
+ linesCRLF = 0;
+
+ int lengthDoc = control->GetLength();
+ const int maxLineNumber = 1000000;
+ char chPrev = ' ';
+ char chNext = control->GetCharAt(0);
+ for (int i = 0; i < lengthDoc; i++)
+ {
+ char ch = chNext;
+ chNext = control->GetCharAt(i + 1);
+ if (ch == '\r')
+ {
+ if (chNext == '\n')
+ linesCRLF++;
+ else
+ linesCR++;
+ }
+ else if (ch == '\n')
+ {
+ if (chPrev != '\r')
+ {
+ linesLF++;
+ }
+ }
+ else if (i > maxLineNumber) // stop the loop if the file contains too many lines
+ return;
+
+ chPrev = ch;
+ }
+}
+
// class constructor
cbEditor::cbEditor(wxWindow* parent, const wxString& filename, EditorColourSet* theme)
: EditorBase(parent, filename),
@@ -1557,7 +1593,6 @@
control->SetMarginWidth(C_CHANGEBAR_MARGIN, 0);
// NOTE: duplicate line in editorconfigurationdlg.cpp (ctor)
- control->SetEOLMode( mgr->ReadInt(_T("/eol/eolmode"), platform::windows ? wxSCI_EOL_CRLF : wxSCI_EOL_LF)); // Windows takes CR+LF, other platforms LF only
control->SetScrollWidthTracking( mgr->ReadBool(_T("/margin/scroll_width_tracking"), false));
control->SetMultipleSelection( mgr->ReadBool(_T("/selection/multi_select"), false));
control->SetAdditionalSelectionTyping(mgr->ReadBool(_T("/selection/multi_typing"), false));
@@ -1575,6 +1610,53 @@
ConfigManager* mgr = Manager::Get()->GetConfigManager(_T("editor"));
+ // set the EOL, fall back value: Windows takes CR+LF, other platforms LF only
+ int eolMode = mgr->ReadInt(_T("/eol/eolmode"), platform::windows ? wxSCI_EOL_CRLF : wxSCI_EOL_LF);
+
+ // The code snippet of auto detect EOL is copied from SciTE's source, CountLineEnds() function
+ // scans the current source file, and counts lines of each EOL style, then finally sets the EOL
+ // by voting logic. In the case of mixed EOL files, we give the user a beep and InfoWindow notification.
+ if (eolMode == 3) //auto detect the EOL
+ {
+ int linesCR;
+ int linesLF;
+ int linesCRLF;
+
+ // count lines of each EOL style
+ CountLineEnds(control, linesCR, linesLF, linesCRLF);
+
+ //voting logic
+ unsigned int delay = 2000;
+ if (((linesLF >= linesCR) && (linesLF > linesCRLF)) || ((linesLF > linesCR) && (linesLF >= linesCRLF)))
+ {
+ eolMode = wxSCI_EOL_LF;
+ if((linesCR>0) || (linesCRLF>0))
+ {
+ wxBell();
+ InfoWindow::Display(_("Mixed Line Endings"), _("Mixed line endings found, setting mode \"LF\""), delay);
+ }
+ }
+ else if (((linesCR >= linesLF) && (linesCR > linesCRLF)) || ((linesCR > linesLF) && (linesCR >= linesCRLF)))
+ {
+ eolMode = wxSCI_EOL_CR;
+ if((linesLF>0) || (linesCRLF>0))
+ {
+ wxBell();
+ InfoWindow::Display(_("Mixed Line Endings"), _("Mixed line endings found, setting mode \"CR\""), delay);
+ }
+ }
+ else if (((linesCRLF >= linesLF) && (linesCRLF > linesCR)) || ((linesCRLF > linesLF) && (linesCRLF >= linesCR)))
+ {
+ eolMode = wxSCI_EOL_CRLF;
+ if((linesCR>0) || (linesLF>0))
+ {
+ wxBell();
+ InfoWindow::Display(_("Mixed Line Endings"), _("Mixed line endings found, setting mode \"CR-LF\""), delay);
+ }
+ }
+ }
+ control->SetEOLMode(eolMode);
+
// Interpret #if/#else/#endif to grey out code that is not active
control->SetProperty(_T("lexer.cpp.track.preprocessor"), mgr->ReadBool(_T("/track_preprocessor"), true) ? _T("1") : _T("0"));
Index: resources/editor_configuration.xrc
===================================================================
--- resources/editor_configuration.xrc (revision 8249)
+++ resources/editor_configuration.xrc (working copy)
@@ -200,6 +200,7 @@
<item>CR LF</item>
<item>CR</item>
<item>LF</item>
+ <item>AUTO</item>
</content>
<style>wxCB_READONLY</style>
</object>
virtual const wxString& GetShortName() const { return m_Shortname; }
// static
void cbEditor::InternalSetEditorStyleAfterFileOpen(cbStyledTextCtrl* control)
... you shouldn't not forget to do nothing (!) if the file dos not contain a line-feed, btw. For this to work, you can return true/false in the method you've introduced.Thanks, here is an improved patch, which handle them in the "else" clause.
Index: cbeditor.cpp
===================================================================
--- cbeditor.cpp (revision 8249)
+++ cbeditor.cpp (working copy)
@@ -731,6 +731,42 @@
END_EVENT_TABLE()
+// Count lines of EOL style in the opened file
+static void CountLineEnds(cbStyledTextCtrl* control, int &linesCR, int &linesLF, int &linesCRLF)
+{
+ linesCR = 0;
+ linesLF = 0;
+ linesCRLF = 0;
+
+ int lengthDoc = control->GetLength();
+ const int maxLengthDoc = 1000000;
+ char chPrev = ' ';
+ char chNext = control->GetCharAt(0);
+ for (int i = 0; i < lengthDoc; i++)
+ {
+ char ch = chNext;
+ chNext = control->GetCharAt(i + 1);
+ if (ch == '\r')
+ {
+ if (chNext == '\n')
+ linesCRLF++;
+ else
+ linesCR++;
+ }
+ else if (ch == '\n')
+ {
+ if (chPrev != '\r')
+ {
+ linesLF++;
+ }
+ }
+ else if (i > maxLengthDoc) // stop the loop if the file contains too many characters
+ return;
+
+ chPrev = ch;
+ }
+}
+
// class constructor
cbEditor::cbEditor(wxWindow* parent, const wxString& filename, EditorColourSet* theme)
: EditorBase(parent, filename),
@@ -1557,7 +1593,6 @@
control->SetMarginWidth(C_CHANGEBAR_MARGIN, 0);
// NOTE: duplicate line in editorconfigurationdlg.cpp (ctor)
- control->SetEOLMode( mgr->ReadInt(_T("/eol/eolmode"), platform::windows ? wxSCI_EOL_CRLF : wxSCI_EOL_LF)); // Windows takes CR+LF, other platforms LF only
control->SetScrollWidthTracking( mgr->ReadBool(_T("/margin/scroll_width_tracking"), false));
control->SetMultipleSelection( mgr->ReadBool(_T("/selection/multi_select"), false));
control->SetAdditionalSelectionTyping(mgr->ReadBool(_T("/selection/multi_typing"), false));
@@ -1575,6 +1610,79 @@
ConfigManager* mgr = Manager::Get()->GetConfigManager(_T("editor"));
+ // set the EOL, fall back value: Windows takes CR+LF, other platforms LF only
+ int eolMode = mgr->ReadInt(_T("/eol/eolmode"), platform::windows ? wxSCI_EOL_CRLF : wxSCI_EOL_LF);
+
+ // The code snippet of auto detect EOL is copied from SciTE's source, CountLineEnds() function
+ // scans the current source file, and counts lines of each EOL style, then finally sets the EOL
+ // by voting logic. In the case of mixed EOL files, we give the user a beep and InfoWindow notification.
+ if (eolMode == 3) //auto detect the EOL
+ {
+ int linesCR;
+ int linesLF;
+ int linesCRLF;
+
+ // count lines of each EOL style
+ CountLineEnds(control, linesCR, linesLF, linesCRLF);
+
+ //voting logic
+ unsigned int delay = 2000;
+ if (((linesLF >= linesCR) && (linesLF > linesCRLF)) || ((linesLF > linesCR) && (linesLF >= linesCRLF)))
+ {
+ eolMode = wxSCI_EOL_LF;
+ if((linesCR>0) || (linesCRLF>0))
+ {
+ wxBell();
+ InfoWindow::Display(_("Mixed Line Endings"), _("Mixed line endings found, setting mode \"LF\""), delay);
+ }
+ }
+ else if (((linesCR >= linesLF) && (linesCR > linesCRLF)) || ((linesCR > linesLF) && (linesCR >= linesCRLF)))
+ {
+ eolMode = wxSCI_EOL_CR;
+ if((linesLF>0) || (linesCRLF>0))
+ {
+ wxBell();
+ InfoWindow::Display(_("Mixed Line Endings"), _("Mixed line endings found, setting mode \"CR\""), delay);
+ }
+ }
+ else if (((linesCRLF >= linesLF) && (linesCRLF > linesCR)) || ((linesCRLF > linesLF) && (linesCRLF >= linesCR)))
+ {
+ eolMode = wxSCI_EOL_CRLF;
+ if((linesCR>0) || (linesLF>0))
+ {
+ wxBell();
+ InfoWindow::Display(_("Mixed Line Endings"), _("Mixed line endings found, setting mode \"CR-LF\""), delay);
+ }
+ }
+ else // in the case of the file does not contain any line-feed, or the file have equally counts of EOL styles
+ {
+ //set to the fall back mode
+ wxString eolModeStr;
+ if (platform::windows)
+ {
+ eolMode = wxSCI_EOL_CRLF;
+ eolModeStr = _T("\"CR-LF\"");
+ }
+ else
+ {
+ eolMode = wxSCI_EOL_LF;
+ eolModeStr = _T("\"LF\"");
+ }
+
+ if((linesCR>0) || (linesLF>0) || (linesCRLF>0)) //equal counts
+ {
+ wxBell();
+ InfoWindow::Display(_("Mixed Line Endings"), _("Mixed line endings found, setting mode ") + eolModeStr, delay);
+ }
+ else //no line-feed found
+ {
+ wxBell();
+ InfoWindow::Display(_("No Line Endings"), _("No Line Endings found, setting mode ") + eolModeStr, delay);
+ }
+ }
+ }
+ control->SetEOLMode(eolMode);
+
// Interpret #if/#else/#endif to grey out code that is not active
control->SetProperty(_T("lexer.cpp.track.preprocessor"), mgr->ReadBool(_T("/track_preprocessor"), true) ? _T("1") : _T("0"));
Index: resources/editor_configuration.xrc
===================================================================
--- resources/editor_configuration.xrc (revision 8249)
+++ resources/editor_configuration.xrc (working copy)
@@ -200,6 +200,7 @@
<item>CR LF</item>
<item>CR</item>
<item>LF</item>
+ <item>AUTO</item>
</content>
<style>wxCB_READONLY</style>
</object>
Logicially, I think it should set the eol mode to "CRLF", because under Windows, the CRLF take precedence. Any good idea about the voting logic? I can't find a better, simple and clean way. ;)Well you can initialise eolMode according the platform and then only change it if you are sure you counted enough different EOL's (so not >=, but only >).
Is it possible to put the new code in a separate function?Maybe even rename CountLineEnds to DetectLineEnds (or alike) and have have it return what eolMode should be set.
Scintilla does not have such feature, but SciTE does....Is it possible to put the new code in a separate function?Maybe even rename CountLineEnds to DetectLineEnds (or alike) and have have it return what eolMode should be set.
Which makes me wonder: Could it be, that scintilla has such a function, too?
Is it possible to put the new code in a separate function?OK, I will did this in the next patch.
OK, I will did this in the next patch.Ok, see this patch. Any further comments?
Index: cbeditor.cpp
===================================================================
--- cbeditor.cpp (revision 8249)
+++ cbeditor.cpp (working copy)
@@ -731,6 +731,95 @@
END_EVENT_TABLE()
+// Count lines of EOL style in the opened file
+static void CountLineEnds(cbStyledTextCtrl* control, int &linesCR, int &linesLF, int &linesCRLF)
+{
+ linesCR = 0;
+ linesLF = 0;
+ linesCRLF = 0;
+
+ int lengthDoc = control->GetLength();
+ const int maxLengthDoc = 1000000;
+ char chPrev = ' ';
+ char chNext = control->GetCharAt(0);
+ for (int i = 0; i < lengthDoc; i++)
+ {
+ char ch = chNext;
+ chNext = control->GetCharAt(i + 1);
+ if (ch == '\r')
+ {
+ if (chNext == '\n')
+ linesCRLF++;
+ else
+ linesCR++;
+ }
+ else if (ch == '\n')
+ {
+ if (chPrev != '\r')
+ {
+ linesLF++;
+ }
+ }
+ else if (i > maxLengthDoc) // stop the loop if the file contains too many characters
+ return;
+
+ chPrev = ch;
+ }
+}
+
+static int DetectLineEnds(cbStyledTextCtrl* control)
+{
+ int eolMode;
+ wxString eolModeStr;
+ // initial EOL mode depend on OS
+ if (platform::windows)
+ {
+ eolMode = wxSCI_EOL_CRLF;
+ eolModeStr = _T("\"CR-LF\"");
+ }
+ else
+ {
+ eolMode = wxSCI_EOL_LF;
+ eolModeStr = _T("\"LF\"");
+ }
+
+ int linesCR;
+ int linesLF;
+ int linesCRLF;
+ // count lines of each EOL style
+ CountLineEnds(control, linesCR, linesLF, linesCRLF);
+
+ // voting logic
+ // if the file does not contain any line-feed or the most largest counts are equal( e.g.: linesLF=5,
+ // linesCRLF=5, linesCR=0 ), then we will use the initial EOL mode
+ if ( (linesLF > linesCR) && (linesLF > linesCRLF) )
+ {
+ eolMode = wxSCI_EOL_LF;
+ eolModeStr = _T("\"LF\"");
+ }
+ else if ( (linesCR > linesLF) && (linesCR > linesCRLF) )
+ {
+ eolMode = wxSCI_EOL_CR;
+ eolModeStr = _T("\"CR\"");
+ }
+ else if ( (linesCRLF > linesLF) && (linesCRLF > linesCR))
+ {
+ eolMode = wxSCI_EOL_CRLF;
+ eolModeStr = _T("\"CR-LF\"");
+ }
+
+ unsigned int delay = 2000;
+ if ( ( (linesCR>0) && (linesCRLF>0) )
+ || ( (linesLF>0) && (linesCRLF>0) )
+ || ( (linesCR>0) && (linesLF>0) ) )
+ {
+ //In mixed EOL file, give the user a beep and InfoWindow notification.
+ wxBell();
+ InfoWindow::Display(_("Mixed Line Endings"), _("Mixed line endings found, setting mode ") + eolModeStr, delay);
+ }
+ return eolMode;
+}
+
// class constructor
cbEditor::cbEditor(wxWindow* parent, const wxString& filename, EditorColourSet* theme)
: EditorBase(parent, filename),
@@ -1557,7 +1646,6 @@
control->SetMarginWidth(C_CHANGEBAR_MARGIN, 0);
// NOTE: duplicate line in editorconfigurationdlg.cpp (ctor)
- control->SetEOLMode( mgr->ReadInt(_T("/eol/eolmode"), platform::windows ? wxSCI_EOL_CRLF : wxSCI_EOL_LF)); // Windows takes CR+LF, other platforms LF only
control->SetScrollWidthTracking( mgr->ReadBool(_T("/margin/scroll_width_tracking"), false));
control->SetMultipleSelection( mgr->ReadBool(_T("/selection/multi_select"), false));
control->SetAdditionalSelectionTyping(mgr->ReadBool(_T("/selection/multi_typing"), false));
@@ -1575,6 +1663,14 @@
ConfigManager* mgr = Manager::Get()->GetConfigManager(_T("editor"));
+ // set the EOL, fall back value: Windows takes CR+LF, other platforms LF only
+ int eolMode = mgr->ReadInt(_T("/eol/eolmode"), platform::windows ? wxSCI_EOL_CRLF : wxSCI_EOL_LF);
+
+ if (eolMode == 3) //auto detect the EOL
+ eolMode = DetectLineEnds(control);
+
+ control->SetEOLMode(eolMode);
+
// Interpret #if/#else/#endif to grey out code that is not active
control->SetProperty(_T("lexer.cpp.track.preprocessor"), mgr->ReadBool(_T("/track_preprocessor"), true) ? _T("1") : _T("0"));
Index: resources/editor_configuration.xrc
===================================================================
--- resources/editor_configuration.xrc (revision 8249)
+++ resources/editor_configuration.xrc (working copy)
@@ -200,6 +200,7 @@
<item>CR LF</item>
<item>CR</item>
<item>LF</item>
+ <item>AUTO</item>
</content>
<style>wxCB_READONLY</style>
</object>
Code+ // set the EOL, fall back value: Windows takes CR+LF, other platforms LF only
The default line-ending on Mac is CR as far as I know.EOL's and he 21st century... still feeling like stone-age... ::)
Sorry to make it a little more complicated.
I think CR or LF are supported on MacOSX, prior to 10.xx, the CR was the default and now with the FreeBSD heritage it is the LF.
But I think most softwares support both and users have files with both endings.
The default line-ending on Mac is CR as far as I know.
Document::Document() {
refCount = 0;
#ifdef _WIN32
eolMode = SC_EOL_CRLF;
#else
eolMode = SC_EOL_LF;
#endif
...
...
Don't we set a CR for wxMAC in a few places? (E.g. the default when the user first uses C::B on a mac?)I think whatever behavior we have should be consistent in all places.This is the old behavior in cbEditor.cpp
control->SetEOLMode( mgr->ReadInt(_T("/eol/eolmode"), platform::windows ? wxSCI_EOL_CRLF : wxSCI_EOL_LF)); // Windows takes CR+LF, other platforms LF only
int eolWindows; // number of Windows line endings, CRLF
int eolLinux; // number of Linux line endings, LF
int eolMacOld; // number of old Mac line endings. CR