Home Download Buy Blog Forum Support

All Line Endings are coverted on file save

All Line Endings are coverted on file save

Postby emilio on Sun Apr 29, 2012 5:04 pm

Hi,

I have noticed that all the line endings (CR/LF) are converted to the selected one (view.line_endings()) on file save.

So, for example if I have a file which has some lines ending with LF and some with CR/LF, even if I don't change anything on the file, when I save it, all the line endings are unified to Unix or Windows

Is this the expected behavior?
Is there any way to avoid this?

Thanks
emilio
 
Posts: 5
Joined: Sun Apr 29, 2012 4:46 pm

Re: All Line Endings are coverted on file save

Postby iamntz on Mon Apr 30, 2012 4:51 am

Maybe it has something to do with
Code: Select all
"default_line_ending": "LF"

setting?
iamntz
 
Posts: 914
Joined: Fri Apr 29, 2011 8:52 am
Location: Romania

Re: All Line Endings are coverted on file save

Postby emilio on Mon Apr 30, 2012 6:06 am

I don't think so, it seems that this setting is to determine the line endings to use in new files

" // Determines what character(s) are used to terminate each line in new files.
// Valid values are 'system' (whatever the OS uses), 'windows' (CRLF) and
// 'unix' (LF only).
"

From what I tested, it doesn't affect existing files

Thanks
emilio
 
Posts: 5
Joined: Sun Apr 29, 2012 4:46 pm

Re: All Line Endings are coverted on file save

Postby jps on Tue May 01, 2012 6:06 am

When saving, all line endings will be written with whatever the current line ending is set to: files with mixed line endings will be opened ok, but the line endings are always normalized in memory when the file is opened, so mixed line endings will never be saved.

If I may ask, do you actually have a desire for a file with mixed line endings, or is it a case that you've got a file with LF line endings, but with a CR character or two inside that is just supposed to be a CR character, and not a line ending as such?
jps
Site Admin
 
Posts: 3070
Joined: Wed Mar 19, 2008 12:33 pm

Re: All Line Endings are coverted on file save

Postby emilio on Wed May 02, 2012 2:04 pm

Thanks for the answer jps

I have a file with mixed line endings. I would like to preserve it as it is. This file is under Version Control Management, so when I change one line, I want only that line changed, so that when I make a diff with a previous version only that line is different. I know I can ignore spaces in a diff and thus ignore line endings, but I need to track space changes also

Isn't it possible to customize the opening of a file, to prevent the line endings normalization?
emilio
 
Posts: 5
Joined: Sun Apr 29, 2012 4:46 pm

Re: All Line Endings are coverted on file save

Postby pete340 on Wed May 02, 2012 2:47 pm

emilio wrote:Thanks for the answer jps

I have a file with mixed line endings. I would like to preserve it as it is. This file is under Version Control Management, so when I change one line, I want only that line changed, so that when I make a diff with a previous version only that line is different. I know I can ignore spaces in a diff and thus ignore line endings, but I need to track space changes also

Isn't it possible to customize the opening of a file, to prevent the line endings normalization?


Is preserving line endings a real requirement, or is it a tool artifact? If the only reason for doing it is to get clean diffs, just change the line endings once and for all and forget it.
pete340
 
Posts: 76
Joined: Mon Oct 10, 2011 9:45 pm

Re: All Line Endings are coverted on file save

Postby emilio on Wed May 02, 2012 4:34 pm

Is to maintain clean the version management of the files

I have several files in this situation, and various developers in different OS that use different line endings (and they use eclipse, that doesn't normalize line endings), so even though I can fix the files, they will mess them up again (i know, we should use a standard line ending for every file, but this is another problem).

So each time I modify a file, I will be modifying lines I didn't even touch, and then when I analyze the history of a file and do a SVN Blame for example it won't say the real last modification
emilio
 
Posts: 5
Joined: Sun Apr 29, 2012 4:46 pm

Re: All Line Endings are coverted on file save

Postby iamntz on Wed May 02, 2012 4:55 pm

I think you are looking for a fix in a wrong place.

First of all, stop using SVN. If you are using SVN you are ugly and stupid :D
Second, you and your team should decide on a standard. Do you also have some team members that use tabs and some are using spaces?

I guess every other editor have line ending settings. Make the changes and you are done. (or just convert everyone on Sublime and everybody wins)
iamntz
 
Posts: 914
Joined: Fri Apr 29, 2011 8:52 am
Location: Romania

Re: All Line Endings are coverted on file save

Postby pete340 on Wed May 02, 2012 5:21 pm

emilio wrote:I have several files in this situation, and various developers in different OS that use different line endings (and they use eclipse, that doesn't normalize line endings), so even though I can fix the files, they will mess them up again (i know, we should use a standard line ending for every file, but this is another problem).


Okay, so it *is* a tool artifact, but a more difficult one that simply a version control issue. Still, since you say that you need to look at whitespace in history, it sounds like you need a uniform approach to line endings. There are ways to do that; SVN can run a script on checkin, and that gives you a hook to "fix" line endings.
pete340
 
Posts: 76
Joined: Mon Oct 10, 2011 9:45 pm

Re: All Line Endings are coverted on file save

Postby emilio on Wed May 02, 2012 7:00 pm

Thanks for the answers

It's not so easy to add the hook, I'm not the admin of the repository, so I won't be able to add the hook, or change SVN to other SCM (in fact we use SVN and Mercurial)

Also I'm not in charge of the team, so I won't be able to convince the developers to use all the same line endings. I totally agree we should have standards, but it is not always so easy when there are lots of developers from different companies, and there is no unique team

So what I need is when I do a modification in a line, just modify that line, and leave the line endings as they are.

I think normalization of line endings is a great feature but I don't really need it, and I don't want it, so if there is no easy way to disable this feature I will look a little more if it is possible to do it through a plugin, but I don't have too much experience on plugins

Any idea on how to avoid the normalization through a plugin?
emilio
 
Posts: 5
Joined: Sun Apr 29, 2012 4:46 pm

Next

Return to Technical Support

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 11 guests