Bug 134852 - RFE: add option to add missing \n at end of file
Summary: RFE: add option to add missing \n at end of file
Status: RESOLVED DUPLICATE of bug 256134
Alias: None
Product: kate
Classification: Applications
Component: part (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR wishlist
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-09-29 15:15 UTC by Rob L
Modified: 2011-08-12 13:38 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rob L 2006-09-29 15:15:55 UTC
Version:           3.3.4 (using KDE KDE 3.4.3KDE 1.2)
Installed from:    Compiled From SourcesCompiled From Sources

An additional blank line is shown in the editor after the last \n in the file.  This means it can be deleted which causes warning messages on some compilers, eg aCC on HP:

Error (future) 690: "...", line 22 # Nonempty source files must end with a newline that is not preceded by a backslash.
Comment 1 Matt Rogers 2006-11-05 16:30:42 UTC
which editor are you using?
Comment 2 Rob L 2006-11-06 10:42:08 UTC
the "Embedded Advanced Text Editor"
Comment 3 Jens Dagerbo 2007-01-02 04:12:52 UTC
I don't understand this report, but the handling of lines in the editor... is in the domain of the editor. Reassigning.
Comment 4 Christoph Cullmann 2007-01-02 07:26:00 UTC
Which is completly correct, in other languages, it is wanted, that the last newline is removable, if you remove it in your C code, it will cause warnings, yes, but that's not a problem of the editor part. Perhaps some option could be added, to always add a newline as last char, if none there in the file. But I think that is really bloat...
Comment 5 Rob L 2007-01-02 11:08:16 UTC
Really?  In which languages wouldn't you use a newline?  The vim editor only omits the last newline if you are editing a binary file (or are in binary mode) - I don't see why you would want to remove it from a text file.

Automatically adding a newline is probably unnecessary as no other editor I've used allows you to accidentally create a file with it missing.  Just making it harder to remove it would be sufficient.
Comment 6 Matthew Woehlke 2007-01-04 17:00:21 UTC
Just to throw my $0.02 in here, I think the right way *is* to always add a trailing new line, or alternatively to always make sure a trailing newline is present, e.g. if you start typing on the last line. In fact, this second idea *might* be really useful because you can always hit ctrl-end to start typing on a new line at the end of the document (but conversely, what if you wanted to start typing at the end of the last line?).

Anyway, I agree with Rob that I think this is much more generically useful than "only for C/C++". Try 'cat <file>' on anything that doesn't end in a newline and then tell me that ASCII files shouldn't end with a newline regardless of language. :-)

I personally don't think this is really that much more "bloat" than 'remove trailing spaces'...
Comment 7 Rob L 2007-01-04 18:09:26 UTC
If you always have a trailing newline, then showing an empty line after it at the end of the file is unecessary (and to me unintuitive).

I would expect ctrl-end to start typing at the end of the last line, with an additional carriage return necessary to start a new line at the end of the file.
Comment 8 Chris Huang-Leaver 2007-04-30 17:41:57 UTC
?confused?

I'm using 2.5.5 of Kate, I'm getting warnings about missing newlines,(with g++) which is really annoying.   The default should be to *always*
if last char is not /n:
   append a /n

to be diplomatic there could be a option to disable this, but the *nix standard is to always end files with a newline.  From the other posts it looks like this has already been done. Is this a new bug? 
Comment 9 Christoph Cullmann 2007-05-03 07:11:08 UTC
There are tons of valid cases where you don't want a \n at file end, yes, even for files you cat, as it is not that cool to have newlines in commandlines you construct via cat or in PHP files, where you don't want \n at end of file sometimes, too (we had even a bug report about this in the past from a web designer developing with PHP where this was fatal...).

There is no standard which says there must be a \n, even emacs doesn't do so...

I am ok with an option, I agree that people using C/C++ and Co. needs this to have a more easy life, but I don't agree at all on it being default on, because that is not expected behaviour, if the user wants only one line without \n in a file, we should respect that, it's completly valid...
Comment 10 Matthew Woehlke 2007-05-03 19:48:20 UTC
Reopened as per Christoph's agreement. We will (eventually :-)) add a *non-default* option to add a \n to the end of the file if it does not end with one.
Comment 11 Andreas Pakulat 2008-01-30 10:25:14 UTC
This would align kate with those other "power" editors, like emacs or vim.
Comment 12 Leo Savernik 2008-01-30 21:47:29 UTC
Please OFF by default.
Comment 13 Andreas Pakulat 2008-01-30 23:13:24 UTC
Of course and as far as I can see nobody suggested otherwise...
Comment 14 Dominik Haumann 2008-01-31 08:49:52 UTC
an option, along with a document variable so it can be set for filetypes/modes :)
Comment 15 FiNeX 2009-02-15 17:22:48 UTC
Is this feature available on KDE 4?
Comment 16 Matthew Woehlke 2009-02-20 23:27:29 UTC
Not yet. Want to help write it? :-)
Comment 17 Dominik Haumann 2011-08-12 13:38:23 UTC
Should be implemented as option.

*** This bug has been marked as a duplicate of bug 256134 ***