Page 1 of 1
By default, TP should not modify files automatically
Posted: Fri Nov 11, 2005 5:00 pm
by aludwin
I use TP to read and sometimes edit source files. We use source control at my company, and once when I was previewing my changes, I found that almost every line had been modified. I eventually discovered that the option "Strip trailing spaces from lines when saving" was on automatically for source files, which meant I had to spend a good 20 minutes going through the entire file and putting all those trailing spaces back so as not to confuse the diff programs.
I think that by default, if I open a file and hit "save," the file's contents should not change unless I've manually changed something. What do you think?
Posted: Fri Nov 11, 2005 6:06 pm
by ben_josephs
You've found Configuration | Preferences... | Document Classes | <Class> | Strip trailing spaces from lines when saving.
If your change doesn't stick, make sure you have only one instance of TextPad running, close all documents, unselect the option again, close and reopen TextPad.
Posted: Fri Nov 11, 2005 6:14 pm
by aludwin
Thanks Ben, that wasn't quite the point though. Disabling the option works as advertised; however, I feel like I shouldn't have had to find it in the first place.
The idea here is, the default behaviour of TP should not be to change your files. The "Strip trailing spaces" option is great, and I would want it in some contexts, but it's a very bad thing to do with source control. Since it's only a minor benefit to have it on by default, but a very big problem (for some users), I think the default should be off.
In general, I think this should apply to any "unexpected" way in which TP might modify your file (eg change \r\n to \n or vice versa, convert tabs to spaces, etc, not that I think it does these things by default anyway). The default should be to leave everything as it is unless the user specifically wants to do something different.
Posted: Fri Nov 11, 2005 7:16 pm
by ben_josephs
You have a good point.
By now, just about nothing in my installation is as it was when it came out of the box. So I didn't recall that the default is as you say.
Posted: Fri Nov 11, 2005 8:17 pm
by MudGuard
I think that by default, if I open a file and hit "save," the file's contents should not change unless I've manually changed something.
I just edited a text file with intentionally some white spaces at the end of the line.
I closed the file.
I set the "Strip trailing spaces" for the appropriate document class.
I opened the file.
I changed nothing.
I hit Ctrl-S to save the file.
Nothing happened.
I added a character.
I hit Ctrl-S to save the file.
The file was saved - the trailing spaces were stripped (as expected).
So Textpad did not change the file's content until I manually changed something. That's exactly what you demand.
Posted: Fri Nov 11, 2005 8:29 pm
by aludwin
This is what I get for not actually trying my testcase before I post. Oops. Nice catch MudGuard.
However, it still doesn't change the thrust of my request. If I'm a new user, and I add a single character and hit CTRL-S, it is
not at all obvious that this will
also strip all the trailing spaces from the rest of the file. (At least, I don't find it obvious). And if I'm a new user editing a source-controlled file, this means a lot of work for me, manually re-adding all those spaces, so my boss doesn't come asking me why I have a 10,000 line diff when all I was supposed to do was change one or two functions. (Yes, our files are 100k+ lines long). This is exactly what happened to me - my change was long, complicated and completely interspersed with all the lines with stripped spaces.
The problem's now fixed (on my computer) but I stand by my claim that the program shouldn't do anything "unexpected" by default. And yes, "Strip Trailing Spaces" is set by default for the C/C++ and Java document classes - exactly the kind of files mostly likely to be under source control. I know that, because I checked this time.
Posted: Fri Nov 11, 2005 10:29 pm
by ben_josephs
I've been hit by precisely this problem. My solution is not to put the spaces back in, but to remove them from a copy of the old file and compare that with the new file. Then (if the only differences that remain are the intended material ones) instruct the source control system to accept all those changes.
aludwin wrote:(Yes, our files are 100k+ lines long).
Time to find some smaller ones!
aludwin wrote:so my boss doesn't come asking me why
Time to find a new one. :-)
Posted: Sun Nov 13, 2005 9:57 pm
by aludwin
I could certainly instruct our source control to accept the changes, but that destroys our history. Imagine someone comparing a version of the file after my change to the a version before - almost every line will be different. (Of course, we could always get a better diff tool, but I don't get to make decisions like that!)
Looks like I'm loosing this battle though...
Posted: Sun Nov 13, 2005 10:58 pm
by ben_josephs
I think, on balance, I agree with you about the default behaviour.
I also feel that you need a better source control system. :-)
Anyway, the person resposible for the big diff is the unhouse-trained programmer who put the trailing spaces in, not the person who tidied them up!