Bug 256134 - JJ: Option: newline at end of file.
Summary: JJ: Option: newline at end of file.
Status: RESOLVED FIXED
Alias: None
Product: kate
Classification: Applications
Component: part (show other bugs)
Version: SVN
Platform: Gentoo Packages Linux
: HI wishlist
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
: 134852 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-11-05 12:00 UTC by Patrick ALLAERT
Modified: 2015-01-18 17:23 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In: 4.9.0


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick ALLAERT 2010-11-05 12:00:00 UTC
Version:           SVN (using KDE 4.5.2) 
OS:                Linux

I would like to have a configuration option so that every files I save ends with a newline on every line, including the last line.
It has been considered a good practice in the Unix/Linux world that every lines end with a newline character. Some editors like Vi don't even propose a choice about this.

Reproducible: Didn't try

Steps to Reproduce:
1. Open Kwrite
2. Types: Line 1<ENTER>Line 2
3. Save the file as "demo.txt"

Actual Results:  
$ od -a demo.txt
0000000   L   i   n   e  sp   1  nl   L   i   n   e  sp   2
0000015

$ wc -l demo.txt
1 demo.txt

Opening the file with vi, it warns that the current file has no EOL:

"demo.txt" [noeol] 2L, 13C

Expected Results:  
$ od -a demo.txt
0000000   L   i   n   e  sp   1  nl   L   i   n   e  sp   2  nl
0000016

$ wc -l demo.txt
2 demo.txt

Saving the file with Vi will add the missing newline character.

Reopening it with Kwrite and showing line numbers, the content is displayed with 3 lines:

1| Line 1
2| Line 2
3|

It looks like a unique newline at the end of a file is interpreted by Kwrite as an empty line.
Comment 1 Milian Wolff 2010-11-05 14:20:20 UTC
I'd love to have that feature, it would be easy to implement but helps a lot. Any takers? I'd help with the implementation, otherwise I'll probably hack it in over the weekend.
Comment 2 Dominik Haumann 2011-08-12 13:38:23 UTC
*** Bug 134852 has been marked as a duplicate of this bug. ***
Comment 3 Patrick ALLAERT 2011-09-22 15:30:13 UTC
Hi Milian, any news about this? I would be glad to contribute myself but haven't enough competencies :(
Comment 4 Dominik Haumann 2012-03-12 21:13:21 UTC
This is implemented in KDE 4.9.

In the Open/Save config dialog, there is now an option called
  [ ] Append newline at end of file on save
By default, it is off.

You can also use a modeline called newline-at-eof: bool [default: false] either in the document itself, or in the .kateconfig file, or in the "Modes & Filetypes" config tab.

If remove-trailing-spaces-on-save is enabled and the last line only contains spaces, no newline is appended.
Comment 5 Paul Fee 2013-02-04 10:28:27 UTC
Thank you for fixing this.  I also see KDevelop (4.4.1, KDE 4.9.5) exposes the same settings for its embedded KatePart.