Merge lp:~trojan295/scratch/Bugfix-1352324 into lp:~elementary-apps/scratch/scratch

Proposed by Damian Czaja
Status: Merged
Approved by: Artem Anufrij
Approved revision: 1402
Merged at revision: 1404
Proposed branch: lp:~trojan295/scratch/Bugfix-1352324
Merge into: lp:~elementary-apps/scratch/scratch
Diff against target: 23 lines (+5/-3)
1 file modified
src/Services/Document.vala (+5/-3)
To merge this branch: bzr merge lp:~trojan295/scratch/Bugfix-1352324
Reviewer Review Type Date Requested Status
Sergey "Shnatsel" Davidoff (community) Needs Fixing
Artem Anufrij (community) Approve
Review via email: mp+240506@code.launchpad.net

Commit message

Adding a '\n' byte to the end of the file when saving.

Description of the change

Adding a '\n' byte to the end of the file when saving.

I have analyzed how looks a text file with multiple empty lines at the end in Vim and it looked like Scratch was losing the last '\n' byte. In Vim the '\n' is added at every end of a file, even without a empty line at the end. Now when you save a file in Scratch, it looks exactly like when you have done it in Vim. None empty line is lost.

To post a comment you must log in.
Revision history for this message
Raphael Isemann (teemperor) wrote :

Does this happen everytime or just with the trim-trailing-whitespace plugin activated?

Anyway, if we could get this fixed it would be cool as it's so annoying to have all those "No new-line at the end of the file" messages in bzr.

Revision history for this message
Damian Czaja (trojan295) wrote :

This fix simply adds a '\n' byte at the end of the file, when you save it. When you put two empty line at the end of the file, save it and reopen, then no lines are removed. As I checked it work with and without the trim-trailing-whitespace plugin. So you can a newline at the end and it will not be removed.

Revision history for this message
Artem Anufrij (artem-anufrij) wrote :

Works as expected. I tested it with plug in and without.

Revision history for this message
Artem Anufrij (artem-anufrij) wrote :

Works as expected. I tested it with plug in and without.

review: Approve
Revision history for this message
Sergey "Shnatsel" Davidoff (shnatsel) wrote :

The "eof" name is confusing: it is usually used to denote the EOF character code, that typically equals to -1 and not the \n character code. Please rename it to "trailing_newline" or some such.

Other than that - great work, thanks!

review: Needs Fixing

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Services/Document.vala'
2--- src/Services/Document.vala 2014-10-18 19:49:49 +0000
3+++ src/Services/Document.vala 2014-11-03 21:30:17 +0000
4@@ -276,8 +276,10 @@
5
6 // Replace old content with the new one
7 try {
8- string s;
9- file.replace_contents (this.source_view.buffer.text.data, null, false, 0, out s);
10+ FileOutputStream fostream = file.replace (null, false, 0);
11+ fostream.write (this.source_view.buffer.text.data);
12+ uint8[] eof = { '\n' };
13+ fostream.write (eof);
14 } catch (Error e) {
15 warning ("Cannot save \"%s\": %s", get_basename (), e.message);
16 return false;
17@@ -724,4 +726,4 @@
18 mounted = false;
19 }
20 }
21-}
22\ No newline at end of file
23+}

Subscribers

People subscribed via source and target branches