Author Topic: Detect file EOL  (Read 513 times)

Offline zach

  • Single posting newcomer
  • *
  • Posts: 8
Detect file EOL
« on: November 24, 2017, 06:20:33 pm »
I'm sorry if this very basic question was asked before, I could not find any help online.

How do I enable automatic EOL detection for a project that needs to specify its own coding style (tab-width, etc) ?
(This project requires a uniform tab-width but has files with different EOL characters due to cross-platform development)

At /Project/Properties/EditorConfig options/ I can't seem to set EOL mode to "AUTO" like I can globally at /Settings/Editor/General Settings/Editor Settings/.
I'm on Ubuntu using Code::Blocks 16.01.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 10403
Re: Detect file EOL
« Reply #1 on: November 24, 2017, 08:53:28 pm »
So what is the exact question? How to make editor-config use auto-eol or something else.
Also what do you expect from auto-eol? At the moment it chooses the eol which is used the most or some other similar heuristic.
As far as I know it doesn't preserve the eol from the current line when you press enter.
<debugger plugin maintainer>
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline zach

  • Single posting newcomer
  • *
  • Posts: 8
Re: Detect file EOL
« Reply #2 on: November 24, 2017, 10:45:36 pm »
So what is the exact question?
There is only one question in my OP which I think makes the issue very clear.

How to make editor-config use auto-eol
Exactly.

At the moment it chooses the eol which is used the most or some other similar heuristic.
This doesn't work.

Also what do you expect from auto-eol?
Obviously I expect CB not trying to be super clever and just set the EOL char to which is most used in the current file like even the simplest editor can do.

Currently you can't have both, change project-specific editor config (tab-width etc) and auto-detect the EOL.
The former is mandatory which overrides the global auto-eol setting and messes up my files with mixed EOLs.

I'm pretty shocked CB doesn't have this to say the least.


EDIT:
I can avoid the issue by manually setting "eol_mode" to "3" in the .cbp project file.
Unfortunately this value gets overwritten on every project property update + save so this is not at all an applicable workaround.
« Last Edit: November 25, 2017, 04:11:10 am by zach »

Offline zach

  • Single posting newcomer
  • *
  • Posts: 8
Re: Detect file EOL
« Reply #3 on: November 24, 2017, 11:48:36 pm »
Maybe related bug:

Closing and reopening a file with mixed EOLs (many CR-LFs occasional LFs) shows a pop-up saying
"Mixed line-endings found, setting mode CR-LF"
but EOL mode of the the editor remains set at LF, which is also my project-specific EOL setting (in lieu of a missing project-wide auto-eol setting).

So maybe the whole issue could qualify more as a bug, which imho doesn't make it less serious..
« Last Edit: November 24, 2017, 11:50:18 pm by zach »

Offline sodev

  • Multiple posting newcomer
  • *
  • Posts: 110
Re: Detect file EOL
« Reply #4 on: November 25, 2017, 06:36:42 am »
Fix your files! Get rid of that mixed EOL style, causes too many issues, also stick to one whitespace mode, at least per file.

Every current rcs converts your files to your current platform style or lets you set a fixed style.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 10403
Re: Detect file EOL
« Reply #5 on: November 25, 2017, 09:19:44 am »
So what is the exact question?
There is only one question in my OP which I think makes the issue very clear.
If it was clear, I wouldn't have asked clarifying questions.

How to make editor-config use auto-eol
Exactly.
Are you talking about this http://editorconfig.org/ ?


<debugger plugin maintainer>
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline zach

  • Single posting newcomer
  • *
  • Posts: 8
Re: Detect file EOL
« Reply #6 on: November 25, 2017, 01:14:56 pm »
Fix your files! Get rid of that mixed EOL style, causes too many issues,
Thanks but I can't modify 60+ files and impose future edits as a project newcomer because my IDE can't handle different EOLs per file.

also stick to one whitespace mode, at least per file.
Of course, that's the whole point of the discussion. I need consistent spaces/tabs project-wide and consistent EOL per file (not project-wide).

Every current rcs converts your files to your current platform style or lets you set a fixed style.
Maybe if I set them up that way but not by default if you mean that (prominent example: Git -> core.autocrlf). Apart from that I do not want this (see above).
« Last Edit: November 25, 2017, 01:39:33 pm by zach »

Offline zach

  • Single posting newcomer
  • *
  • Posts: 8
Re: Detect file EOL
« Reply #7 on: November 25, 2017, 01:16:25 pm »
Are you talking about this http://editorconfig.org/ ?

I'm talking about the CB EditorConfig plugin ???
(libEditorConfig.so)
Installed either by default or coming with contrib, accessed by
/Project/Properties/EditorConfig options/

At least I found the source so I can (hopefully) fix it myself:
https://github.com/editorconfig/editorconfig-codeblocks
« Last Edit: November 25, 2017, 01:26:04 pm by zach »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 10403
Re: Detect file EOL
« Reply #8 on: November 25, 2017, 02:16:23 pm »
The source code is in the src/plugins/contrib/EditorConfig folder.

The problem is that the "editor config" spec doesn't know about this auto-eol mode as far as I can see.
If you have an editor config you're either setting dos or unix style for eol.
So you need to make contributions to "editor config" first and then you could do changes to codeblocks' integration of editor config.

I could have skipped this from the editor config docs, because I've not read it in detail.
« Last Edit: November 25, 2017, 02:17:59 pm by oBFusCATed »
<debugger plugin maintainer>
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline zach

  • Single posting newcomer
  • *
  • Posts: 8
Re: Detect file EOL
« Reply #9 on: November 25, 2017, 05:54:45 pm »
The source code is in the src/plugins/contrib/EditorConfig folder.
That was helpful, thanks.

The problem is that the "editor config" spec doesn't know about this auto-eol mode as far as I can see.
If you have an editor config you're either setting dos or unix style for eol.
So you need to make contributions to "editor config" first and then you could do changes to codeblocks' integration of editor config.
In that case an option to just respect the global setting (/Settings/Editor/) could make sense. I have a feeling that the behavior described in post 4 may be related to a clash between project and global settings.

Offline zach

  • Single posting newcomer
  • *
  • Posts: 8
Re: Detect file EOL
« Reply #10 on: December 01, 2017, 10:35:38 pm »
Finally found some minutes on it...

Firstly the CB contrib-plugin EditorConfig and the EditorConfig project have nothing in common besides the name. The contrib-plugin shares its settings in the CB project file wheareas EditorConfig requires a third party plugin (called "EditorConfig Code::Blocks" to make it even more confusing) and uses a file named ".editorconfig" for settings which many editors support (looks quite handy).


------
Concerning the issue of this thread, there was indeed a clash between project-wide settings of the contrib plugin and global settings if EOL mode was set globally to AUTO (see post 4).

The fix is as easy as adding a new item to the combobox named "Use global settings"
This will store value 3 for eol_mode in the project.

We can do this because EditorConfig just ignores the new value on apply (to the active editor), which is exactly what we want because of the clash with global settings:
Code: [Select]
bool EditorConfig::ApplyEditorSettings(EditorBase* eb)
{
    ...
    if      (m_ECSettings[prj].eol_mode == wxSCI_EOL_CRLF)
            control->SetEOLMode(wxSCI_EOL_CRLF);
    else if (m_ECSettings[prj].eol_mode == wxSCI_EOL_CR)
            control->SetEOLMode(wxSCI_EOL_CR);
    else if (m_ECSettings[prj].eol_mode == wxSCI_EOL_LF)
            control->SetEOLMode(wxSCI_EOL_LF);
    ...
}

Backward combatiblity (open newer projects with older CB) is given, the plugin will just fall back to mode CRLF in case of value 3 for eol.


------
I opened a ticket but I'm not awfully interested of having this fixed in the main branch (not going to use CB very much though its a great IDE) but also didn't want to hold this back.

I doubt this is required but I include a tiny git patch, there is no use for me to set-up a inferior VCS (mmv) for this and the diff-to-svn-patch script didn't work for me.
« Last Edit: December 01, 2017, 10:45:20 pm by zach »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 10403
Re: Detect file EOL
« Reply #11 on: December 02, 2017, 10:40:23 am »
I opened a ticket but I'm not awfully interested of having this fixed in the main branch (not going to use CB very much though its a great IDE) but also didn't want to hold this back.
I'm not sure how to interpret this. Why post a patch for something you don't need?
<debugger plugin maintainer>
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline zach

  • Single posting newcomer
  • *
  • Posts: 8
Re: Detect file EOL
« Reply #12 on: December 02, 2017, 02:06:54 pm »
I'm not sure how to interpret this. Why post a patch for something you don't need?
I'm sorry but is this question meant to be serious? ;D
Maybe to make others not run into the same thing if this is a potential fix?

... but also didn't want to hold this back.

Anyways, as a non-native speaker above post and sourceforge shenanigans took me 10x longer, than fixing this stupid issue for me, so you can be sure I'll never do that again in the next 4 month I'm going to use CB.

I sincerely wish you guys all the best.