User forums > Help
EOL issue, the EOL should be automatically detected, and make consistent
ollydbg:
I just want to have a feature request:
When I open a LF file, when I hit enters, it should add many lines of LF.
When I open a CRLF file, when I hit enters, it should add many lines of CRLF.
But currently, I see that I can't do that, the EOL is fixed, and either I result a mixed EOF file, or I need to set the EOL in the editor when I open each projects.
This is really annoying.
I have see such report 6 years ago, see: Feature Request: Auto EOL Mode, but I don't think it was implemented.
BTW: I see that Notepad++ have such feature. Will C::B finally implement it?
EDIT: I also find on in the feature request:
Leave EOL format be
EDIT: I just tested the SciTE 3.2.1, and it works as what I want "leave as it is".
ollydbg:
I dig the code a little, and see that the EOL is set in the editor before the file is loaded.
sdk\cbeditor.cpp
--- Code: ---// 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);
}
--- End code ---
Here, it just read the "eol/eolmode" from the configure file.
So, my question is: If we have add an option like "leave the eol as it is", then we need to Set the EOL after the file is loaded, right?
If I remove the line "control->SetEOLMode....", I think the control should have a eol which is consistent to the opened file?
ollydbg:
Hi, guys, I dig it further, and I found that the SciTE use this code:
In its source: C:\scite321\scite\src\SciTEIO.cxx
--- Code: ---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);
}
}
--- End code ---
So, it change the EOL dynamically.
BTW: currently, by default, under Windows, it use CRLF, see:
[scintilla] default eol mode on OS X - Google Groups
thomas:
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).
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"? You basically want anything typed into a file to be whatever the file was before, correct?
Also, what if the file, like many files from OSS projects is mixed already?
ollydbg:
--- Quote from: thomas on August 24, 2012, 03:29:45 pm ---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).
--- End quote ---
Hi, thomas, sorry about the confusion, I'm not a English native speaker, so my English may be poor.
--- Quote ---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"?
--- End quote ---
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.
Here is an example, when I open a file, which has LF styled EOL, by default, if I have the configuration with "CR LF" in the editor setting, the new added line in the editor will have "CR LF" ending, so, the file becomes "LF" and "CR LF" mixed.
See the image below: (The new added empty line have CRLF styled EOL, but the original file have all LF styled EOL)
On the other side, if you set the editor as "LF" format, then you will have the same issue that an original CRLF styled file will contains many LF styled lines.
--- Quote ---You basically want anything typed into a file to be whatever the file was before, correct?
--- End quote ---
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.
Currently, both SciTE and NotePad++ has this feature, so I believe C::B should have this feature too.
--- Quote ---Also, what if the file, like many files from OSS projects is mixed already?
--- End quote ---
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.
OK about my brain? :)
EDIT:
It looks like to determine which EOL is used for a mixed EOL files, SciTe use a voting
--- Code: ---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;
}
}
--- End code ---
Navigation
[0] Message Index
[#] Next page
Go to full version